Comment: | New ivar naming convention.
ivars are now named like this: thisIsAnIVar. If an accessor exists for |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
37db8f0fb3f7d28b75ff59fa3e884b54 |
User & Date: | js on 2010-04-17 22:27:17 |
Other Links: | manifest | tags |
2010-04-17
| ||
23:04 | Add properties to interfaces. Only used if supported by the compiler. check-in: f3e7291fad user: js tags: trunk | |
22:27 | New ivar naming convention. check-in: 37db8f0fb3 user: js tags: trunk | |
21:43 | Better method names for file- and stream-related exceptions. check-in: 1f19713fd3 user: js tags: trunk | |
Modified src/OFApplication.h from [9f252190f8] to [ad7af612fb].
︙ | ︙ | |||
39 40 41 42 43 44 45 | @end /** * \brief Represents the application as an object. */ @interface OFApplication: OFObject { | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | @end /** * \brief Represents the application as an object. */ @interface OFApplication: OFObject { OFString *programName; OFMutableArray *arguments; id delegate; } /** * \return The only OFApplication instance in the application */ |
︙ | ︙ |
Modified src/OFApplication.m from [e27d763715] to [cbba891989].
︙ | ︙ | |||
90 91 92 93 94 95 96 | - (void)setArgumentCount: (int)argc andArgumentValues: (char**)argv { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; int i; | | | | | 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 | - (void)setArgumentCount: (int)argc andArgumentValues: (char**)argv { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; int i; [programName release]; [arguments release]; programName = [[OFString alloc] initWithCString: argv[0]]; arguments = [[OFMutableArray alloc] init]; for (i = 1; i < argc; i++) [arguments addObject: [OFString stringWithCString: argv[i]]]; [pool release]; } - (OFString*)programName { return [[programName retain] autorelease]; } - (OFArray*)arguments { return [[arguments retain] autorelease]; } |
︙ | ︙ |
Modified src/OFArray.h from [df7759c80b] to [1188c860b8].
︙ | ︙ | |||
173 174 175 176 177 178 179 | /// \cond internal @interface OFArrayEnumerator: OFEnumerator { OFDataArray *array; size_t count; unsigned long mutations; | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | /// \cond internal @interface OFArrayEnumerator: OFEnumerator { OFDataArray *array; size_t count; unsigned long mutations; unsigned long *mutationsPtr; size_t pos; } - initWithDataArray: (OFDataArray*)data mutationsPointer: (unsigned long*)mutations_ptr; @end /// \endcond |
︙ | ︙ |
Modified src/OFArray.m from [9a33d23f86] to [af5a656bb6].
︙ | ︙ | |||
364 365 366 367 368 369 370 | [super dealloc]; } @end /// \cond internal @implementation OFArrayEnumerator - initWithDataArray: (OFDataArray*)array_ | | | | | | | 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | [super dealloc]; } @end /// \cond internal @implementation OFArrayEnumerator - initWithDataArray: (OFDataArray*)array_ mutationsPointer: (unsigned long*)mutationsPtr_; { self = [super init]; array = array_; count = [array_ count]; mutations = *mutationsPtr_; mutationsPtr = mutationsPtr_; return self; } - (id)nextObject { if (mutationsPtr != NULL && *mutationsPtr != mutations) @throw [OFEnumerationMutationException newWithClass: isa]; if (pos < count) return *(OFObject**)[array itemAtIndex: pos++]; return nil; } - (void)reset { if (mutationsPtr != NULL && *mutationsPtr != mutations) @throw [OFEnumerationMutationException newWithClass: isa]; pos = 0; } @end /// \endcond |
Modified src/OFAutoreleasePool.h from [4c33f3246c] to [80b6b20e53].
︙ | ︙ | |||
19 20 21 22 23 24 25 | * The OFAutoreleasePool class is a class that keeps track of objects that will * be released when the autorelease pool is released. * * Every thread has its own stack of autorelease pools. */ @interface OFAutoreleasePool: OFObject { | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * The OFAutoreleasePool class is a class that keeps track of objects that will * be released when the autorelease pool is released. * * Every thread has its own stack of autorelease pools. */ @interface OFAutoreleasePool: OFObject { OFMutableArray *objects; OFAutoreleasePool *next, *prev; } /** * Adds an object to the autorelease pool at the top of the thread-specific * stack. * |
︙ | ︙ |
Modified src/OFDataArray.h from [3674b3e199] to [eabc1b70df].
︙ | ︙ | |||
16 17 18 19 20 21 22 | * * If you plan to store large hunks of data, you should consider using * OFBigDataArray, which allocates the memory in pages rather than in bytes. */ @interface OFDataArray: OFObject <OFCopying> { char *data; | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * * If you plan to store large hunks of data, you should consider using * OFBigDataArray, which allocates the memory in pages rather than in bytes. */ @interface OFDataArray: OFObject <OFCopying> { char *data; size_t itemSize; size_t count; } /** * Creates a new OFDataArray whose items all have the same size. * * \param is The size of each element in the OFDataArray |
︙ | ︙ |
Modified src/OFDataArray.m from [cb1099f8ad] to [138d001cd6].
︙ | ︙ | |||
41 42 43 44 45 46 47 | c = isa; [super dealloc]; @throw [OFInvalidArgumentException newWithClass: c selector: _cmd]; } data = NULL; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 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 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 | c = isa; [super dealloc]; @throw [OFInvalidArgumentException newWithClass: c selector: _cmd]; } data = NULL; itemSize = is; return self; } - (size_t)count { return count; } - (size_t)itemSize { return itemSize; } - (void*)cArray { return data; } - (void*)itemAtIndex: (size_t)index { if (index >= count) @throw [OFOutOfRangeException newWithClass: isa]; return data + index * itemSize; } - (void*)firstItem { if (data == NULL || count == 0) return NULL; return data; } - (void*)lastItem { if (data == NULL || count == 0) return NULL; return data + (count - 1) * itemSize; } - (void)addItem: (void*)item { if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + 1 withSize: itemSize]; memcpy(data + count * itemSize, item, itemSize); count++; } - (void)addItem: (void*)item atIndex: (size_t)index { [self addNItems: 1 fromCArray: item atIndex: index]; } - (void)addNItems: (size_t)nitems fromCArray: (void*)carray { if (nitems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nitems withSize: itemSize]; memcpy(data + count * itemSize, carray, nitems * itemSize); count += nitems; } - (void)addNItems: (size_t)nitems fromCArray: (void*)carray atIndex: (size_t)index { if (nitems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nitems withSize: itemSize]; memmove(data + (index + nitems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, carray, nitems * itemSize); count += nitems; } - (void)removeItemAtIndex: (size_t)index { [self removeNItems: 1 atIndex: index]; } - (void)removeNItems: (size_t)nitems { if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nitems; @try { data = [self resizeMemory: data toNItems: count withSize: itemSize]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ [e dealloc]; } } - (void)removeNItems: (size_t)nitems atIndex: (size_t)index { if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemSize, data + (index + nitems) * itemSize, (count - index - nitems) * itemSize); count -= nitems; @try { data = [self resizeMemory: data toNItems: count withSize: itemSize]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ [e dealloc]; } } - copy { OFDataArray *new = [[OFDataArray alloc] initWithItemSize: itemSize]; [new addNItems: count fromCArray: data]; return new; } - (BOOL)isEqual: (OFObject*)obj { if (![obj isKindOfClass: [OFDataArray class]]) return NO; if ([(OFDataArray*)obj count] != count || [(OFDataArray*)obj itemSize] != itemSize) return NO; if (memcmp([(OFDataArray*)obj cArray], data, count * itemSize)) return NO; return YES; } - (of_comparison_result_t)compare: (OFDataArray*)ary { int cmp; size_t ary_count, min_count; if (![ary isKindOfClass: [OFDataArray class]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if ([ary itemSize] != itemSize) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; ary_count = [ary count]; min_count = (count > ary_count ? ary_count : count); if ((cmp = memcmp(data, [ary cArray], min_count * itemSize)) == 0) { if (count > ary_count) return OF_ORDERED_DESCENDING; if (count < ary_count) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } if (cmp > 0) return OF_ORDERED_DESCENDING; else return OF_ORDERED_ASCENDING; } - (uint32_t)hash { uint32_t hash; size_t i; OF_HASH_INIT(hash); for (i = 0; i < count * itemSize; i++) OF_HASH_ADD(hash, ((char*)data)[i]); OF_HASH_FINALIZE(hash); return hash; } @end @implementation OFBigDataArray - (void)addItem: (void*)item { size_t nsize, lastpagebyte; if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemSize) @throw [OFOutOfRangeException newWithClass: isa]; lastpagebyte = of_pagesize - 1; nsize = ((count + 1) * itemSize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; memcpy(data + count * itemSize, item, itemSize); count++; size = nsize; } - (void)addNItems: (size_t)nitems fromCArray: (void*)carray { size_t nsize, lastpagebyte; if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException newWithClass: isa]; lastpagebyte = of_pagesize - 1; nsize = ((count + nitems) * itemSize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; memcpy(data + count * itemSize, carray, nitems * itemSize); count += nitems; size = nsize; } - (void)addNItems: (size_t)nitems fromCArray: (void*)carray atIndex: (size_t)index { size_t nsize, lastpagebyte; if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException newWithClass: isa]; lastpagebyte = of_pagesize - 1; nsize = ((count + nitems) * itemSize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toNItems: nsize withSize: itemSize]; memmove(data + (index + nitems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, carray, nitems * itemSize); count += nitems; size = nsize; } - (void)removeNItems: (size_t)nitems { size_t nsize, lastpagebyte; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nitems; lastpagebyte = of_pagesize - 1; nsize = (count * itemSize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; size = nsize; } - (void)removeNItems: (size_t)nitems atIndex: (size_t)index { size_t nsize, lastpagebyte; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemSize, data + (index + nitems) * itemSize, (count - index - nitems) * itemSize); count -= nitems; lastpagebyte = of_pagesize - 1; nsize = (count * itemSize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; size = nsize; } - copy { OFDataArray *new = [[OFBigDataArray alloc] initWithItemSize: itemSize]; [new addNItems: count fromCArray: data]; return new; } @end |
Modified src/OFDictionary.h from [af6491b4d3] to [56783e6894].
︙ | ︙ | |||
161 162 163 164 165 166 167 | /// \cond internal @interface OFDictionaryEnumerator: OFEnumerator { struct of_dictionary_bucket **data; uint32_t size; unsigned long mutations; | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | /// \cond internal @interface OFDictionaryEnumerator: OFEnumerator { struct of_dictionary_bucket **data; uint32_t size; unsigned long mutations; unsigned long *mutationsPtr; uint32_t pos; } - initWithData: (struct of_dictionary_bucket**)data size: (uint32_t)size mutationsPointer: (unsigned long*)mutations_ptr; @end |
︙ | ︙ |
Modified src/OFDictionary.m from [469dcb5227] to [0083ef4288].
︙ | ︙ | |||
680 681 682 683 684 685 686 | } @end /// \cond internal @implementation OFDictionaryEnumerator - initWithData: (struct of_dictionary_bucket**)data_ size: (uint32_t)size_ | | | | | | | | 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | } @end /// \cond internal @implementation OFDictionaryEnumerator - initWithData: (struct of_dictionary_bucket**)data_ size: (uint32_t)size_ mutationsPointer: (unsigned long*)mutationsPtr_ { self = [super init]; data = data_; size = size_; mutations = *mutationsPtr_; mutationsPtr = mutationsPtr_; return self; } - (void)reset { if (mutationsPtr != NULL && *mutationsPtr != mutations) @throw [OFEnumerationMutationException newWithClass: isa]; pos = 0; } @end @implementation OFDictionaryObjectEnumerator - (id)nextObject { if (mutationsPtr != NULL && *mutationsPtr != mutations) @throw [OFEnumerationMutationException newWithClass: isa]; for (; pos < size && (data[pos] == NULL || data[pos] == DELETED); pos++); if (pos < size) return data[pos++]->object; else return nil; } @end @implementation OFDictionaryKeyEnumerator - (id)nextObject { if (mutationsPtr != NULL && *mutationsPtr != mutations) @throw [OFEnumerationMutationException newWithClass: isa]; for (; pos < size && (data[pos] == NULL || data[pos] == DELETED); pos++); if (pos < size) return data[pos++]->key; else return nil; } @end /// \endcond |
Modified src/OFExceptions.h from [f8a53f2bce] to [6329d53dc9].
︙ | ︙ | |||
47 48 49 50 51 52 53 | * the OFAllocFailedException. * * IMPORTANT: Exceptions do NOT use OFAutoreleasePools and can't be autoreleased * either! You have to make sure to dealloc the exception in your \@catch block! */ @interface OFException: OFObject { | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | * the OFAllocFailedException. * * IMPORTANT: Exceptions do NOT use OFAutoreleasePools and can't be autoreleased * either! You have to make sure to dealloc the exception in your \@catch block! */ @interface OFException: OFObject { Class inClass; OFString *string; } /** * Creates a new exception. * * \param class_ The class of the object which caused the exception |
︙ | ︙ | |||
83 84 85 86 87 88 89 | @end /** * \brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | @end /** * \brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { size_t requestedSize; } /** * \param class_ The class of the object which caused the exception * \param size The size of the memory that couldn't be allocated * \return A new no memory exception */ |
︙ | ︙ | |||
242 243 244 245 246 247 248 | /** * \brief An exception indicating a file couldn't be opened. */ @interface OFOpenFileFailedException: OFException { OFString *path; OFString *mode; | | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | /** * \brief An exception indicating a file couldn't be opened. */ @interface OFOpenFileFailedException: OFException { OFString *path; OFString *mode; int errNo; } /** * \param class_ The class of the object which caused the exception * \param path A string with the path of the file tried to open * \param mode A string with the mode in which the file should have been opened * \return A new open file failed exception |
︙ | ︙ | |||
288 289 290 291 292 293 294 | @end /** * \brief An exception indicating a read or write to a stream failed. */ @interface OFReadOrWriteFailedException: OFException { | | | | 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | @end /** * \brief An exception indicating a read or write to a stream failed. */ @interface OFReadOrWriteFailedException: OFException { size_t requestedSize; int errNo; } /** * \param class_ The class of the object which caused the exception * \param size The requested size of the data that couldn't be read / written * \return A new open file failed exception */ |
︙ | ︙ | |||
338 339 340 341 342 343 344 | @end /** * \brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { | | | | 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 | @end /** * \brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { int errNo; } /** * \return The errno from when the exception was created */ - (int)errNo; @end /** * \brief An exception indicating a directory couldn't be created. */ @interface OFCreateDirectoryFailedException: OFException { OFString *path; int errNo; } /** * \param class_ The class of the object which caused the exception * \param path A string with the path of the directory which couldn't be created * \return A new create directory failed exception */ |
︙ | ︙ | |||
392 393 394 395 396 397 398 | /** * \brief An exception indicating that changing the mode of a file failed. */ @interface OFChangeFileModeFailedException: OFException { OFString *path; mode_t mode; | | | 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | /** * \brief An exception indicating that changing the mode of a file failed. */ @interface OFChangeFileModeFailedException: OFException { OFString *path; mode_t mode; int errNo; } /** * \param class_ The class of the object which caused the exception * \param path The path of the file * \param mode The new mode for the file * \return An initialized change file mode failed exception |
︙ | ︙ | |||
442 443 444 445 446 447 448 | * \brief An exception indicating that changing the owner of a file failed. */ @interface OFChangeFileOwnerFailedException: OFException { OFString *path; uid_t owner; gid_t group; | | | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | * \brief An exception indicating that changing the owner of a file failed. */ @interface OFChangeFileOwnerFailedException: OFException { OFString *path; uid_t owner; gid_t group; int errNo; } /** * \param class_ The class of the object which caused the exception * \param path The path of the file * \param owner The new owner for the file * \param group The new group for the file |
︙ | ︙ | |||
498 499 500 501 502 503 504 | #endif /** * \brief An exception indicating that renaming a file failed. */ @interface OFRenameFileFailedException: OFException { | | | | | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | #endif /** * \brief An exception indicating that renaming a file failed. */ @interface OFRenameFileFailedException: OFException { OFString *sourcePath; OFString *destinationPath; int errNo; } /** * \param class_ The class of the object which caused the exception * \param src The original path * \param dst The new path * \return A new rename file failed exception |
︙ | ︙ | |||
547 548 549 550 551 552 553 | /** * \brief An exception indicating that deleting a file failed. */ @interface OFDeleteFileFailedException: OFException { OFString *path; | | | 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | /** * \brief An exception indicating that deleting a file failed. */ @interface OFDeleteFileFailedException: OFException { OFString *path; int errNo; } /** * \param class_ The class of the object which caused the exception * \param path The path of the file * \return A new delete file failed exception */ |
︙ | ︙ | |||
585 586 587 588 589 590 591 | #ifndef _WIN32 /** * \brief An exception indicating that creating a link failed. */ @interface OFLinkFailedException: OFException { | | | | | 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | #ifndef _WIN32 /** * \brief An exception indicating that creating a link failed. */ @interface OFLinkFailedException: OFException { OFString *sourcePath; OFString *destinationPath; int errNo; } /** * \param class_ The class of the object which caused the exception * \param src The source for the link * \param dest The destination for the link * \return A new link failed exception |
︙ | ︙ | |||
633 634 635 636 637 638 639 | @end /** * \brief An exception indicating that creating a symlink failed. */ @interface OFSymlinkFailedException: OFException { | | | | | 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | @end /** * \brief An exception indicating that creating a symlink failed. */ @interface OFSymlinkFailedException: OFException { OFString *sourcePath; OFString *destinationPath; int errNo; } /** * \param class_ The class of the object which caused the exception * \param src The source for the symlink * \param dest The destination for the symlink * \return A new symlink failed exception |
︙ | ︙ | |||
703 704 705 706 707 708 709 | /** * \brief An exception indicating the translation of an address failed. */ @interface OFAddressTranslationFailedException: OFException { OFString *node; OFString *service; | | | 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | /** * \brief An exception indicating the translation of an address failed. */ @interface OFAddressTranslationFailedException: OFException { OFString *node; OFString *service; int errNo; } /** * \param class_ The class of the object which caused the exception * \param node The node for which translation was requested * \param service The service of the node for which translation was requested * \return A new address translation failed exception |
︙ | ︙ | |||
751 752 753 754 755 756 757 | /** * \brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { OFString *node; OFString *service; | | | 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | /** * \brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { OFString *node; OFString *service; int errNo; } /** * \param class_ The class of the object which caused the exception * \param node The node to which the connection failed * \param service The service on the node to which the connection failed * \return A new connection failed exception |
︙ | ︙ | |||
800 801 802 803 804 805 806 | * \brief An exception indicating that binding a socket failed. */ @interface OFBindFailedException: OFException { OFString *node; OFString *service; int family; | | | 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | * \brief An exception indicating that binding a socket failed. */ @interface OFBindFailedException: OFException { OFString *node; OFString *service; int family; int errNo; } /** * \param class_ The class of the object which caused the exception * \param node The node on which binding failed * \param service The service on which binding failed * \param family The family for which binnding failed |
︙ | ︙ | |||
855 856 857 858 859 860 861 | @end /** * \brief An exception indicating that listening on the socket failed. */ @interface OFListenFailedException: OFException { | | | | 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | @end /** * \brief An exception indicating that listening on the socket failed. */ @interface OFListenFailedException: OFException { int backLog; int errNo; } /** * \param class_ The class of the object which caused the exception * \param backlog The requested size of the back log * \return A new listen failed exception */ |
︙ | ︙ | |||
893 894 895 896 897 898 899 | @end /** * \brief An exception indicating that accepting a connection failed. */ @interface OFAcceptFailedException: OFException { | | | 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | @end /** * \brief An exception indicating that accepting a connection failed. */ @interface OFAcceptFailedException: OFException { int errNo; } /** * \return The errno from when the exception was created */ - (int)errNo; @end |
︙ | ︙ |
Modified src/OFExceptions.m from [7ab9c8b826] to [a6eb967aa3].
︙ | ︙ | |||
28 29 30 31 32 33 34 | #import "OFExceptions.h" #import "OFString.h" #import "OFTCPSocket.h" #ifndef _WIN32 # include <errno.h> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | 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 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 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 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 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 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 | #import "OFExceptions.h" #import "OFString.h" #import "OFTCPSocket.h" #ifndef _WIN32 # include <errno.h> # define GET_ERRNO errno # ifndef HAVE_THREADSAFE_GETADDRINFO # define GET_AT_ERRNO h_errno # else # define GET_AT_ERRNO errno # endif # define GET_SOCK_ERRNO errno # define ERRFMT "Error string was: %s" # define ERRPARAM strerror(errNo) # ifndef HAVE_THREADSAFE_GETADDRINFO # define AT_ERRPARAM hstrerror(errNo) # else # define AT_ERRPARAM strerror(errNo) # endif #else # include <windows.h> # define GET_ERRNO GetLastError() # define GET_AT_ERRNO WSAGetLastError() # define GET_SOCK_ERRNO WSAGetLastError() # define ERRFMT "Error code was: %d" # define ERRPARAM errNo # define AT_ERRPARAM errNo #endif #import "asprintf.h" @implementation OFAllocFailedException + (Class)class { return self; } - (OFString*)string { return @"Allocating an object failed!"; } @end @implementation OFException + newWithClass: (Class)class_ { return [[self alloc] initWithClass: class_]; } - init { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ { self = [super init]; class_ = class_; return self; } - (void)dealloc { [string release]; [super dealloc]; } - (Class)inClass { return inClass; } - (OFString*)string { return string; } - autorelease { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } @end @implementation OFOutOfMemoryException + newWithClass: (Class)class_ size: (size_t)size { return [[self alloc] initWithClass: class_ size: size]; } - initWithClass: (Class)class_ size: (size_t)size { self = [super initWithClass: class_]; requestedSize = size; return self; } - (OFString*)string { if (string != nil) return string; if (requestedSize) string = [[OFString alloc] initWithFormat: @"Could not allocate %zu bytes in class %s!", requestedSize, [inClass className]]; else string = [[OFString alloc] initWithFormat: @"Could not allocate enough memory in class %s!", [inClass className]]; return string; } - (size_t)requestedSize { return requestedSize; } @end @implementation OFEnumerationMutationException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Object of class %s was mutated during enumeration!", [inClass className]]; return string; } @end @implementation OFMemoryNotPartOfObjectException + newWithClass: (Class)class_ pointer: (void*)ptr { return [[self alloc] initWithClass: class_ pointer: ptr]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ pointer: (void*)ptr { self = [super initWithClass: class_]; pointer = ptr; return self; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Memory at %p was not allocated as part of object of class %s, " @"thus the memory allocation was not changed! It is also possible " @"that there was an attempt to free the same memory twice.", pointer, [inClass className]]; return string; } - (void*)pointer { return pointer; } @end @implementation OFNotImplementedException + newWithClass: (Class)class_ selector: (SEL)selector { return [[self alloc] initWithClass: class_ selector: selector]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ selector: (SEL)selector_ { self = [super initWithClass: class_]; selector = selector_; return self; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The method %s of class %s is not or not fully implemented!", sel_getName(selector), [inClass className]]; return string; } @end @implementation OFOutOfRangeException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Value out of range in class %s!", [inClass className]]; return string; } @end @implementation OFInvalidArgumentException + newWithClass: (Class)class_ selector: (SEL)selector_ { return [[self alloc] initWithClass: class_ selector: selector_]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ selector: (SEL)selector_ { self = [super initWithClass: class_]; selector = selector_; return self; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The argument for method %s of class %s is invalid!", sel_getName(selector), [inClass className]]; return string; } @end @implementation OFInvalidEncodingException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The encoding is invalid for class %s!", [inClass className]]; return string; } @end @implementation OFInvalidFormatException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The format is invalid for class %s!", [inClass className]]; return string; } @end @implementation OFMalformedXMLException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The parser in class %s encountered malformed or invalid XML!", [inClass className]]; return string; } @end @implementation OFInitializationFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Initialization failed for class %s!", [inClass className]]; return string; } @end @implementation OFOpenFileFailedException + newWithClass: (Class)class_ path: (OFString*)path mode: (OFString*)mode { return [(OFOpenFileFailedException*)[self alloc] initWithClass: class_ path: path mode: mode]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ mode: (OFString*)mode_ { self = [super initWithClass: class_]; path = [path_ copy]; mode = [mode_ copy]; errNo = GET_ERRNO; return self; } - (void)dealloc { [path release]; [mode release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to open file %s with mode %s in class %s! " ERRFMT, [path cString], [mode cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)path { return path; } - (OFString*)mode { return mode; } @end @implementation OFReadOrWriteFailedException + newWithClass: (Class)class_ size: (size_t)size { return [[self alloc] initWithClass: class_ size: size]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ size: (size_t)size { self = [super initWithClass: class_]; requestedSize = size; if ([class_ isSubclassOfClass: [OFSocket class]]) errNo = GET_SOCK_ERRNO; else errNo = GET_ERRNO; return self; } - (int)errNo { return errNo; } - (size_t)requestedSize { return requestedSize; } @end @implementation OFReadFailedException - (OFString*)string { if (string != nil) return string;; string = [[OFString alloc] initWithFormat: @"Failed to read %zu bytes in class %s! " ERRFMT, requestedSize, [inClass className], ERRPARAM]; return string; } @end @implementation OFWriteFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to write %zu bytes in class %s! " ERRFMT, requestedSize, [inClass className], ERRPARAM]; return string; } @end @implementation OFSeekFailedException - initWithClass: (Class)class_ { self = [super initWithClass: class_]; errNo = GET_ERRNO; return self; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Seeking failed in class %s! " ERRFMT, [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } @end @implementation OFCreateDirectoryFailedException + newWithClass: (Class)class_ path: (OFString*)path_ { return [[self alloc] initWithClass: class_ path: path_]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ { self = [super initWithClass: class_]; path = [path_ copy]; errNo = GET_ERRNO; return self; } - (void)dealloc { [path release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to create directory %s in class %s! " ERRFMT, [path cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)path { return path; } @end @implementation OFChangeFileModeFailedException + newWithClass: (Class)class_ path: (OFString*)path mode: (mode_t)mode { return [(OFChangeFileModeFailedException*)[self alloc] initWithClass: class_ path: path mode: mode]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ mode: (mode_t)mode_ { self = [super initWithClass: class_]; path = [path_ copy]; mode = mode_; errNo = GET_ERRNO; return self; } - (void)dealloc { [path release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to change mode for file %s to %d in class %s! " ERRFMT, [path cString], mode, [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)path { return path; } - (mode_t)mode { return mode; } @end #ifndef _WIN32 @implementation OFChangeFileOwnerFailedException + newWithClass: (Class)class_ path: (OFString*)path owner: (uid_t)owner group: (gid_t)group { return [[self alloc] initWithClass: class_ path: path owner: owner group: group]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ owner: (uid_t)owner_ group: (gid_t)group_ { self = [super initWithClass: class_]; path = [path_ copy]; owner = owner_; group = group_; errNo = GET_ERRNO; return self; } - (void)dealloc { [path release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to change owner for file %s to %d:%d in class %s! " ERRFMT, [path cString], owner, group, [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)path { return path; } - (uid_t)owner { return owner; } - (gid_t)group { return group; } @end #endif @implementation OFRenameFileFailedException + newWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dst { return [[self alloc] initWithClass: class_ sourcePath: src destinationPath: dst]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dst { self = [super initWithClass: class_]; sourcePath = [src copy]; destinationPath = [dst copy]; errNo = GET_ERRNO; return self; } - (void)dealloc { [sourcePath release]; [destinationPath release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to rename file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)sourcePath { return sourcePath; } - (OFString*)destinationPath; { return destinationPath; } @end @implementation OFDeleteFileFailedException + newWithClass: (Class)class_ path: (OFString*)path_ { return [[self alloc] initWithClass: class_ path: path_]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ { self = [super initWithClass: class_]; path = [path_ copy]; errNo = GET_ERRNO; return self; } - (void)dealloc { [path release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to delete file %s in class %s! " ERRFMT, [path cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)path { return path; } @end #ifndef _WIN32 @implementation OFLinkFailedException + newWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dest { return [[self alloc] initWithClass: class_ sourcePath: src destinationPath: dest]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dest { self = [super initWithClass: class_]; sourcePath = [src copy]; destinationPath = [dest copy]; errNo = GET_ERRNO; return self; } - (void)dealloc { [sourcePath release]; [destinationPath release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to link file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)sourcePath { return sourcePath; } - (OFString*)destinationPath { return destinationPath; } @end @implementation OFSymlinkFailedException + newWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dest { return [[self alloc] initWithClass: class_ sourcePath: src destinationPath: dest]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dest { self = [super initWithClass: class_]; sourcePath = [src copy]; destinationPath = [dest copy]; errNo = GET_ERRNO; return self; } - (void)dealloc { [sourcePath release]; [destinationPath release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to symlink file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)sourcePath { return sourcePath; } - (OFString*)destinationPath { return destinationPath; } @end #endif @implementation OFSetOptionFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Setting an option in class %s failed!", [inClass className]]; return string; } @end @implementation OFNotConnectedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The socket of type %s is not connected or bound!", [inClass className]]; return string; } @end @implementation OFAlreadyConnectedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The socket of type %s is already connected or bound and thus " @"can't be connected or bound again!", [inClass className]]; return string; } @end @implementation OFAddressTranslationFailedException + newWithClass: (Class)class_ node: (OFString*)node service: (OFString*)service { return [[self alloc] initWithClass: class_ node: node service: service]; } - initWithClass: (Class)class_ { self = [super initWithClass: class_]; errNo = GET_AT_ERRNO; return self; } - initWithClass: (Class)class_ node: (OFString*)node_ service: (OFString*)service_ { self = [super initWithClass: class_]; node = [node_ copy]; service = [service_ copy]; errNo = GET_AT_ERRNO; return self; } - (void)dealloc { [node release]; |
︙ | ︙ | |||
1052 1053 1054 1055 1056 1057 1058 | string = [[OFString alloc] initWithFormat: @"The service %s on %s could not be translated to an " @"address in class %s. This means that either the node was " @"not found, there is no such service on the node, there " @"was a problem with the name server, there was a problem " @"with your network connection or you specified an invalid " @"node or service. " ERRFMT, [service cString], | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 | string = [[OFString alloc] initWithFormat: @"The service %s on %s could not be translated to an " @"address in class %s. This means that either the node was " @"not found, there is no such service on the node, there " @"was a problem with the name server, there was a problem " @"with your network connection or you specified an invalid " @"node or service. " ERRFMT, [service cString], [node cString], [inClass className], AT_ERRPARAM]; else string = [[OFString alloc] initWithFormat: @"An address translation failed in class %s! " ERRFMT, [inClass className], AT_ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)node { return node; } - (OFString*)service { return service; } @end @implementation OFConnectionFailedException + newWithClass: (Class)class_ node: (OFString*)node service: (OFString*)service { return [[self alloc] initWithClass: class_ node: node service: service]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ node: (OFString*)node_ service: (OFString*)service_ { self = [super initWithClass: class_]; node = [node_ copy]; service = [service_ copy]; errNo = GET_SOCK_ERRNO; return self; } - (void)dealloc { [node release]; [service release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"A connection to service %s on node %s could not be established " @"in class %s! " ERRFMT, [node cString], [service cString], [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)node { return node; } - (OFString*)service { return service; } @end @implementation OFBindFailedException + newWithClass: (Class)class_ node: (OFString*)node service: (OFString*)service family: (int)family { return [[self alloc] initWithClass: class_ node: node service: service family: family]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ node: (OFString*)node_ service: (OFString*)service_ family: (int)family_ { self = [super initWithClass: class_]; node = [node_ copy]; service = [service_ copy]; family = family_; errNo = GET_SOCK_ERRNO; return self; } - (void)dealloc { [node release]; [service release]; [super dealloc]; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Binding service %s on node %s using family %d failed in class " @"%s! " ERRFMT, [service cString], [node cString], family, [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } - (OFString*)node { return node; } - (OFString*)service { return service; } - (int)family { return family; } @end @implementation OFListenFailedException + newWithClass: (Class)class_ backLog: (int)backlog { return [[self alloc] initWithClass: class_ backLog: backlog]; } - initWithClass: (Class)class_ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithClass: (Class)class_ backLog: (int)backlog { self = [super initWithClass: class_]; backLog = backlog; errNo = GET_SOCK_ERRNO; return self; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to listen in socket of type %s with a back log of %d! " ERRFMT, [inClass className], backLog, ERRPARAM]; return string; } - (int)errNo { return errNo; } - (int)backLog { return backLog; } @end @implementation OFAcceptFailedException - initWithClass: (Class)class_ { self = [super initWithClass: class_]; errNo = GET_SOCK_ERRNO; return self; } - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Failed to accept connection in socket of type %s! " ERRFMT, [inClass className], ERRPARAM]; return string; } - (int)errNo { return errNo; } @end @implementation OFThreadStartFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Starting a thread of class %s failed!", [inClass className]]; return string; } @end @implementation OFThreadJoinFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Joining a thread of class %s failed! Most likely, another thread " @"already waits for the thread to join.", [inClass className]]; return string; } @end @implementation OFThreadStillRunningException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"Deallocation of a thread of type %s was tried, even though it " @"was still running", [inClass className]]; return string; } @end @implementation OFMutexLockFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"A mutex could not be locked in class %s", [inClass className]]; return string; } @end @implementation OFMutexUnlockFailedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"A mutex could not be unlocked in class %s", [inClass className]]; return string; } @end @implementation OFHashAlreadyCalculatedException - (OFString*)string { if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The hash has already been calculated in class %s and thus no new " @"data can be added", [inClass className]]; return string; } @end |
Modified src/OFMutableString.m from [7172dc591d] to [920953956a].
︙ | ︙ | |||
37 38 39 40 41 42 43 | { of_unichar_t c; of_unichar_t *ustr; size_t ulen, nlen, clen; size_t i, j, d; char *nstr; | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | { of_unichar_t c; of_unichar_t *ustr; size_t ulen, nlen, clen; size_t i, j, d; char *nstr; if (!isUTF8) { assert(table_size >= 1); uint8_t *p = (uint8_t*)string + length; uint8_t t; while (--p >= (uint8_t*)string) if ((t = table[0][*p]) != 0) |
︙ | ︙ | |||
127 128 129 130 131 132 133 | [self freeMemory: string]; len = strlen(str); switch (of_string_check_utf8(str, len)) { case 0: | | | | | | | 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 | [self freeMemory: string]; len = strlen(str); switch (of_string_check_utf8(str, len)) { case 0: isUTF8 = NO; break; case 1: isUTF8 = YES; break; case -1: string = NULL; length = 0; isUTF8 = NO; @throw [OFInvalidEncodingException newWithClass: isa]; } length = len; string = [self allocMemoryWithSize: length + 1]; memcpy(string, str, length + 1); } - (void)appendCString: (const char*)str { size_t strlength; strlength = strlen(str); switch (of_string_check_utf8(str, strlength)) { case 1: isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException newWithClass: isa]; } string = [self resizeMemory: string toSize: length + strlength + 1]; memcpy(string + length, str, strlength + 1); length += strlength; } - (void)appendCString: (const char*)str withLength: (size_t)len { if (len > strlen(str)) @throw [OFOutOfRangeException newWithClass: isa]; switch (of_string_check_utf8(str, len)) { case 1: isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException newWithClass: isa]; } string = [self resizeMemory: string toSize: length + len + 1]; |
︙ | ︙ | |||
262 263 264 265 266 267 268 | /* We reverse all bytes and restore UTF-8 later, if necessary */ for (i = 0, j = length - 1; i < len; i++, j--) { string[i] ^= string[j]; string[j] ^= string[i]; string[i] ^= string[j]; } | | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | /* We reverse all bytes and restore UTF-8 later, if necessary */ for (i = 0, j = length - 1; i < len; i++, j--) { string[i] ^= string[j]; string[j] ^= string[i]; string[i] ^= string[j]; } if (!isUTF8) { madvise(string, len, MADV_NORMAL); return; } for (i = 0; i < length; i++) { /* ASCII */ if (OF_LIKELY(!(string[i] & 0x80))) |
︙ | ︙ | |||
353 354 355 356 357 358 359 | [self _applyTable: of_unicode_lower_table withSize: OF_UNICODE_LOWER_TABLE_SIZE]; } - (void)removeCharactersFromIndex: (size_t)start toIndex: (size_t)end { | | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | [self _applyTable: of_unicode_lower_table withSize: OF_UNICODE_LOWER_TABLE_SIZE]; } - (void)removeCharactersFromIndex: (size_t)start toIndex: (size_t)end { if (isUTF8) { start = of_string_index_to_position(string, start, length); end = of_string_index_to_position(string, end, length); } if (start > end) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; |
︙ | ︙ |
Modified src/OFSeekableStream.h from [8903116140] to [9408d385d6].
︙ | ︙ | |||
19 20 21 22 23 24 25 | * IMPORTANT: If you want to subclass this, override _seekToOffset:, * _seekForwardWithOffset: and _seekToOffsetRelativeToEnd:, but nothing else. * Those are not defined in the headers, but do the actual work. * OFSeekableStream uses those and makes them work together with the caching of * OFStream. If you override these methods without the _ prefix, you *WILL* * break caching, get broken results and seek to the wrong position! */ | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * IMPORTANT: If you want to subclass this, override _seekToOffset:, * _seekForwardWithOffset: and _seekToOffsetRelativeToEnd:, but nothing else. * Those are not defined in the headers, but do the actual work. * OFSeekableStream uses those and makes them work together with the caching of * OFStream. If you override these methods without the _ prefix, you *WILL* * break caching, get broken results and seek to the wrong position! */ @interface OFSeekableStream: OFStream {} /** * Seeks to the specified absolute offset. * * \param offset The offset in bytes */ - (void)seekToOffset: (off_t)offset; |
︙ | ︙ |
Modified src/OFSeekableStream.m from [ebbb4dbb54] to [13775b9538].
︙ | ︙ | |||
34 35 36 37 38 39 40 | - (void)seekToOffset: (off_t)offset { [self flushWriteBuffer]; [self _seekToOffset: offset]; [self freeMemory: cache]; cache = NULL; | | | | | | 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 | - (void)seekToOffset: (off_t)offset { [self flushWriteBuffer]; [self _seekToOffset: offset]; [self freeMemory: cache]; cache = NULL; cacheLen = 0; } - (off_t)seekForwardWithOffset: (off_t)offset { off_t ret; [self flushWriteBuffer]; ret = [self _seekForwardWithOffset: offset - cacheLen]; [self freeMemory: cache]; cache = NULL; cacheLen = 0; return ret; } - (off_t)seekToOffsetRelativeToEnd: (off_t)offset { off_t ret; [self flushWriteBuffer]; ret = [self _seekToOffsetRelativeToEnd: offset]; [self freeMemory: cache]; cache = NULL; cacheLen = 0; return ret; } @end |
Modified src/OFStream.h from [fde24b0fcf] to [a95808e9fd].
︙ | ︙ | |||
23 24 25 26 27 28 29 | * _writeNBytes:fromBuffer: and _atEndOfStream, but nothing else. Those are not * defined in the headers, but do the actual work. OFStream uses those and does * all the caching and other stuff. If you override these methods without the * _ prefix, you *WILL* break caching and get broken results! */ @interface OFStream: OFObject { | | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * _writeNBytes:fromBuffer: and _atEndOfStream, but nothing else. Those are not * defined in the headers, but do the actual work. OFStream uses those and does * all the caching and other stuff. If you override these methods without the * _ prefix, you *WILL* break caching and get broken results! */ @interface OFStream: OFObject { char *cache, *wBuffer; size_t cacheLen, wBufferLen; BOOL useWBuffer; } /** * Returns a boolean whether the end of the stream has been reached. * * \return A boolean whether the end of the stream has been reached */ |
︙ | ︙ |
Modified src/OFStream.m from [86b9b6684c] to [451931881c].
︙ | ︙ | |||
33 34 35 36 37 38 39 | self = [super init]; if (isa == [OFStream class]) @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; cache = NULL; | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | self = [super init]; if (isa == [OFStream class]) @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; cache = NULL; wBuffer = NULL; return self; } - (BOOL)_atEndOfStream { @throw [OFNotImplementedException newWithClass: isa |
︙ | ︙ | |||
73 74 75 76 77 78 79 | - (size_t)readNBytes: (size_t)size intoBuffer: (char*)buf { if (cache == NULL) return [self _readNBytes: size intoBuffer: buf]; | | | | | | | | | 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 | - (size_t)readNBytes: (size_t)size intoBuffer: (char*)buf { if (cache == NULL) return [self _readNBytes: size intoBuffer: buf]; if (size >= cacheLen) { size_t ret = cacheLen; memcpy(buf, cache, cacheLen); [self freeMemory: cache]; cache = NULL; cacheLen = 0; return ret; } else { char *tmp = [self allocMemoryWithSize: cacheLen - size]; memcpy(tmp, cache + size, cacheLen - size); memcpy(buf, cache, size); [self freeMemory: cache]; cache = tmp; cacheLen -= size; return size; } } - (void)readExactlyNBytes: (size_t)size intoBuffer: (char*)buf |
︙ | ︙ | |||
236 237 238 239 240 241 242 | { size_t i, len, ret_len; char *ret_c, *tmp, *tmp2; OFString *ret; /* Look if there's a line or \0 in our cache */ if (cache != NULL) { | | | | | | | | | | | 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 | { size_t i, len, ret_len; char *ret_c, *tmp, *tmp2; OFString *ret; /* Look if there's a line or \0 in our cache */ if (cache != NULL) { for (i = 0; i < cacheLen; i++) { if (OF_UNLIKELY(cache[i] == '\n' || cache[i] == '\0')) { ret_len = i; if (i > 0 && cache[i - 1] == '\r') ret_len--; ret = [OFString stringWithCString: cache encoding: encoding length: ret_len]; tmp = [self allocMemoryWithSize: cacheLen - i - 1]; if (tmp != NULL) memcpy(tmp, cache + i + 1, cacheLen - i - 1); [self freeMemory: cache]; cache = tmp; cacheLen -= i + 1; return ret; } } } /* Read until we get a newline or \0 */ tmp = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { if ([self _atEndOfStream]) { if (cache == NULL) return nil; ret_len = cacheLen; if (ret_len > 0 && cache[ret_len - 1] == '\r') ret_len--; ret = [OFString stringWithCString: cache encoding: encoding length: ret_len]; [self freeMemory: cache]; cache = NULL; cacheLen = 0; return ret; } len = [self _readNBytes: of_pagesize intoBuffer: tmp]; /* Look if there's a newline or \0 */ for (i = 0; i < len; i++) { if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) { ret_len = cacheLen + i; ret_c = [self allocMemoryWithSize: ret_len]; if (cache != NULL) memcpy(ret_c, cache, cacheLen); memcpy(ret_c + cacheLen, tmp, i); if (ret_len > 0 && ret_c[ret_len - 1] == '\r') ret_len--; @try { ret = [OFString |
︙ | ︙ | |||
324 325 326 327 328 329 330 | allocMemoryWithSize: len - i - 1]; if (tmp2 != NULL) memcpy(tmp2, tmp + i + 1, len - i - 1); [self freeMemory: cache]; cache = tmp2; | | | | | | | 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 | allocMemoryWithSize: len - i - 1]; if (tmp2 != NULL) memcpy(tmp2, tmp + i + 1, len - i - 1); [self freeMemory: cache]; cache = tmp2; cacheLen = len - i - 1; return ret; } } /* There was no newline or \0 */ cache = [self resizeMemory: cache toSize: cacheLen + len]; /* * It's possible that cacheLen + len is 0 and thus * cache was set to NULL by resizeMemory:toSize:. */ if (cache != NULL) memcpy(cache + cacheLen, tmp, len); cacheLen += len; } } @finally { [self freeMemory: tmp]; } /* Get rid of a warning, never reached anyway */ assert(0); |
︙ | ︙ | |||
376 377 378 379 380 381 382 | if (delim_len == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; /* Look if there's something in our cache */ if (cache != NULL) { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 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 | if (delim_len == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; /* Look if there's something in our cache */ if (cache != NULL) { for (i = 0; i < cacheLen; i++) { if (cache[i] != delim[j++]) j = 0; if (j == delim_len || cache[i] == '\0') { if (cache[i] == '\0') delim_len = 1; ret = [OFString stringWithCString: cache encoding: encoding length: i + 1 - delim_len]; tmp = [self allocMemoryWithSize: cacheLen - i - 1]; if (tmp != NULL) memcpy(tmp, cache + i + 1, cacheLen - i - 1); [self freeMemory: cache]; cache = tmp; cacheLen -= i + 1; return ret; } } } /* Read until we get the delimiter or \0 */ tmp = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { if ([self _atEndOfStream]) { if (cache == NULL) return nil; ret = [OFString stringWithCString: cache encoding: encoding length: cacheLen]; [self freeMemory: cache]; cache = NULL; cacheLen = 0; return ret; } len = [self _readNBytes: of_pagesize intoBuffer: tmp]; /* Look if there's the delimiter or \0 */ for (i = 0; i < len; i++) { if (tmp[i] != delim[j++]) j = 0; if (j == delim_len || tmp[i] == '\0') { if (tmp[i] == '\0') delim_len = 1; ret_len = cacheLen + i + 1 - delim_len; ret_c = [self allocMemoryWithSize: ret_len]; if (cache != NULL && cacheLen <= ret_len) memcpy(ret_c, cache, cacheLen); else if (cache != NULL) memcpy(ret_c, cache, ret_len); if (i >= delim_len) memcpy(ret_c + cacheLen, tmp, i + 1 - delim_len); @try { ret = [OFString stringWithCString: ret_c encoding: encoding length: ret_len]; } @finally { [self freeMemory: ret_c]; } tmp2 = [self allocMemoryWithSize: len - i - 1]; if (tmp2 != NULL) memcpy(tmp2, tmp + i + 1, len - i - 1); [self freeMemory: cache]; cache = tmp2; cacheLen = len - i - 1; return ret; } } /* Neither the delimiter nor \0 was found */ cache = [self resizeMemory: cache toSize: cacheLen + len]; /* * It's possible that cacheLen + len is 0 and thus * cache was set to NULL by resizeMemory:toSize:. */ if (cache != NULL) memcpy(cache + cacheLen, tmp, len); cacheLen += len; } } @finally { [self freeMemory: tmp]; } /* Get rid of a warning, never reached anyway */ assert(0); } - (void)bufferWrites { useWBuffer = YES; } - (void)flushWriteBuffer { if (wBuffer == NULL) return; [self _writeNBytes: wBufferLen fromBuffer: wBuffer]; [self freeMemory: wBuffer]; wBuffer = NULL; wBufferLen = 0; useWBuffer = NO; } - (size_t)writeNBytes: (size_t)size fromBuffer: (const char*)buf { if (!useWBuffer) return [self _writeNBytes: size fromBuffer: buf]; else { wBuffer = [self resizeMemory: wBuffer toSize: wBufferLen + size]; memcpy(wBuffer + wBufferLen, buf, size); wBufferLen += size; return size; } } - (void)writeInt8: (uint8_t)int8 { |
︙ | ︙ |
Modified src/OFString.h from [fe46512cb7] to [1828092a6a].
︙ | ︙ | |||
37 38 39 40 41 42 43 | @interface OFString: OFObject <OFCopying, OFMutableCopying> { char *string; unsigned int length; #if defined(OF_APPLE_RUNTIME) && __LP64__ int _unused; #endif | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | @interface OFString: OFObject <OFCopying, OFMutableCopying> { char *string; unsigned int length; #if defined(OF_APPLE_RUNTIME) && __LP64__ int _unused; #endif BOOL isUTF8; } /** * \return A new autoreleased OFString */ + string; |
︙ | ︙ |
Modified src/OFString.m from [f0e2960871] to [7f39ded0e7].
︙ | ︙ | |||
338 339 340 341 342 343 344 | @throw e; } switch (encoding) { case OF_STRING_ENCODING_UTF_8: switch (of_string_check_utf8(str, length)) { case 1: | | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | @throw e; } switch (encoding) { case OF_STRING_ENCODING_UTF_8: switch (of_string_check_utf8(str, length)) { case 1: isUTF8 = YES; break; case -1:; /* * We can't use [super dealloc] on OS X here. * Compiler bug? Anyway, [self dealloc] will do here as * we don't reimplement dealloc. */ |
︙ | ︙ | |||
402 403 404 405 406 407 408 | */ Class c = isa; [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } | | | 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | */ Class c = isa; [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } isUTF8 = YES; chr_bytes = of_string_unicode_to_utf8(chr, buf); if (chr_bytes == 0) { /* * We can't use [super dealloc] on OS X * here. Compiler bug? Anyway, * [self dealloc] will do here as we |
︙ | ︙ | |||
505 506 507 508 509 510 511 | */ @throw [OFOutOfMemoryException newWithClass: c]; } length = t; switch (of_string_check_utf8(string, length)) { case 1: | | | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | */ @throw [OFOutOfMemoryException newWithClass: c]; } length = t; switch (of_string_check_utf8(string, length)) { case 1: isUTF8 = YES; break; case -1:; Class c = isa; free(string); [super dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } |
︙ | ︙ | |||
550 551 552 553 554 555 556 | Class c; self = [super init]; len = [first cStringLength]; switch (of_string_check_utf8([first cString], len)) { case 1: | | | | 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | Class c; self = [super init]; len = [first cStringLength]; switch (of_string_check_utf8([first cString], len)) { case 1: isUTF8 = YES; break; case -1: c = isa; [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } length += len; va_copy(args2, args); while ((component = va_arg(args2, OFString*)) != nil) { len = [component cStringLength]; length += 1 + len; switch (of_string_check_utf8([component cString], len)) { case 1: isUTF8 = YES; break; case -1: c = isa; [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } } |
︙ | ︙ | |||
607 608 609 610 611 612 613 | self = [super init]; string = (char*)[str cString]; length = [str cStringLength]; switch (of_string_check_utf8(string, length)) { case 1: | | | 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | self = [super init]; string = (char*)[str cString]; length = [str cStringLength]; switch (of_string_check_utf8(string, length)) { case 1: isUTF8 = YES; break; case -1:; Class c = isa; [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } |
︙ | ︙ |
Modified src/OFTCPSocket.h from [bc6d0d6e26] to [19e54da62b].
︙ | ︙ | |||
24 25 26 27 28 29 30 | @class OFString; /** * \brief A class which provides functions to create and use TCP sockets. */ @interface OFTCPSocket: OFSocket { | | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | @class OFString; /** * \brief A class which provides functions to create and use TCP sockets. */ @interface OFTCPSocket: OFSocket { struct sockaddr *sockAddr; socklen_t sockAddrLen; } /** * Connect the OFTCPSocket to the specified destination. * * \param service The service on the node to connect to * \param node The node to connect to |
︙ | ︙ |
Modified src/OFTCPSocket.m from [fe6d461e93] to [dd20905993].
︙ | ︙ | |||
49 50 51 52 53 54 55 | #endif - init { self = [super init]; sock = INVALID_SOCKET; | | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #endif - init { self = [super init]; sock = INVALID_SOCKET; sockAddr = NULL; return self; } - (void)connectToService: (OFString*)service onNode: (OFString*)node { |
︙ | ︙ | |||
345 346 347 348 349 350 351 | if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { [newsock dealloc]; @throw [OFAcceptFailedException newWithClass: isa]; } newsock->sock = s; | | | | | | | | 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 388 389 390 391 392 393 394 395 396 397 398 399 400 | if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { [newsock dealloc]; @throw [OFAcceptFailedException newWithClass: isa]; } newsock->sock = s; newsock->sockAddr = addr; newsock->sockAddrLen = addrlen; return newsock; } - (void)setKeepAlivesEnabled: (BOOL)enable { int v = enable; if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) @throw [OFSetOptionFailedException newWithClass: isa]; } - (OFString*)remoteAddress { if (sockAddr == NULL || sockAddrLen == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; #ifdef HAVE_THREADSAFE_GETADDRINFO char *node = [self allocMemoryWithSize: NI_MAXHOST]; @try { if (getnameinfo(sockAddr, sockAddrLen, node, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) @throw [OFAddressTranslationFailedException newWithClass: isa]; return [OFString stringWithCString: node]; } @finally { [self freeMemory: node]; } #else char *node; # ifdef OF_THREADS [mutex lock]; @try { # endif node = inet_ntoa(((struct sockaddr_in*)sockAddr)->sin_addr); if (node == NULL) @throw [OFAddressTranslationFailedException newWithClass: isa]; return [OFString stringWithCString: node]; # ifdef OF_THREADS |
︙ | ︙ | |||
412 413 414 415 416 417 418 | { if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa]; close(sock); sock = INVALID_SOCKET; | | | | | 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | { if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa]; close(sock); sock = INVALID_SOCKET; [self freeMemory: sockAddr]; sockAddr = NULL; sockAddrLen = 0; } - (void)dealloc { if (sock != INVALID_SOCKET) [self close]; [super dealloc]; } @end |
Modified src/OFXMLElement.h from [4b04a1a1a1] to [52cc35da36].
︙ | ︙ | |||
20 21 22 23 24 25 26 | /** * \brief A representation of an attribute of an XML element as an object. */ @interface OFXMLAttribute: OFObject { OFString *prefix; OFString *name; | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /** * \brief A representation of an attribute of an XML element as an object. */ @interface OFXMLAttribute: OFObject { OFString *prefix; OFString *name; OFString *namespace; OFString *stringValue; } /** * \param name The name of the attribute * \param prefix The prefix of the attribute * \param ns The namespace of the attribute * \param value The string value of the attribute |
︙ | ︙ | |||
80 81 82 83 84 85 86 | * * The OFXMLElement represents an XML element as an object which can be * modified and converted back to XML again. */ @interface OFXMLElement: OFObject { OFString *name; | | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | * * The OFXMLElement represents an XML element as an object which can be * modified and converted back to XML again. */ @interface OFXMLElement: OFObject { OFString *name; OFMutableArray *attributes; OFString *stringValue; OFMutableArray *children; } /** * \param name The name for the element * \return A new autorelease OFXMLElement with the specified element name */ |
︙ | ︙ |
Modified src/OFXMLElement.m from [748986426d] to [d6b729bcd1].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" int _OFXMLElement_reference; @implementation OFXMLAttribute | | | | | | | | | | | | | | | | | | | | | | | | 20 21 22 23 24 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" int _OFXMLElement_reference; @implementation OFXMLAttribute + attributeWithName: (OFString*)name prefix: (OFString*)prefix namespace: (OFString*)ns stringValue: (OFString*)value { return [[[self alloc] initWithName: name prefix: prefix namespace: ns stringValue: value] autorelease]; } - initWithName: (OFString*)name_ prefix: (OFString*)prefix_ namespace: (OFString*)ns stringValue: (OFString*)value { self = [super init]; name = [name_ copy]; prefix = [prefix_ copy]; namespace = [ns copy]; stringValue = [value copy]; return self; } - (void)dealloc { [name release]; [prefix release]; [namespace release]; [stringValue release]; [super dealloc]; } - (OFString*)name { return [[name copy] autorelease]; } - (OFString*)prefix { return [[prefix copy] autorelease]; } - (OFString*)namespace { return [[namespace copy] autorelease]; } - (OFString*)stringValue { return [[stringValue copy] autorelease]; } @end @implementation OFXMLElement + elementWithName: (OFString*)name_ { return [[[self alloc] initWithName: name_] autorelease]; } + elementWithName: (OFString*)name stringValue: (OFString*)stringval { return [[[self alloc] initWithName: name stringValue: stringval] autorelease]; } - init { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - initWithName: (OFString*)name_ { self = [super init]; name = [name_ copy]; return self; } - initWithName: (OFString*)name_ stringValue: (OFString*)stringval { self = [super init]; name = [name_ copy]; stringValue = [stringval copy]; return self; } - (OFString*)string { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; |
︙ | ︙ | |||
133 134 135 136 137 138 139 | /* Start of tag */ *str_c = '<'; memcpy(str_c + 1, [name cString], [name cStringLength]); i = [name cStringLength] + 1; /* Attributes */ | | | | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | /* Start of tag */ *str_c = '<'; memcpy(str_c + 1, [name cString], [name cStringLength]); i = [name cStringLength] + 1; /* Attributes */ attrs_carray = [attributes cArray]; attrs_count = [attributes count]; for (j = 0; j < attrs_count; j++) { /* FIXME: Add namespace support */ OFString *attr_name = [attrs_carray[j] name]; tmp = [[attrs_carray[j] stringValue] stringByXMLEscaping]; len += [attr_name cStringLength] + [tmp cStringLength] + 4; |
︙ | ︙ | |||
164 165 166 167 168 169 170 | i += [tmp cStringLength]; str_c[i++] = '\''; [pool releaseObjects]; } /* Childen */ | | | | | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | i += [tmp cStringLength]; str_c[i++] = '\''; [pool releaseObjects]; } /* Childen */ if (stringValue != nil || children != nil) { if (stringValue != nil) tmp = [stringValue stringByXMLEscaping]; else if (children != nil) { OFXMLElement **children_carray = [children cArray]; size_t children_count = [children count]; IMP append; tmp = [OFMutableString string]; append = [tmp methodForSelector: |
︙ | ︙ | |||
217 218 219 220 221 222 223 | [self freeMemory: str_c]; } return ret; } - (void)addAttribute: (OFXMLAttribute*)attr { | | | | | | | | 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 | [self freeMemory: str_c]; } return ret; } - (void)addAttribute: (OFXMLAttribute*)attr { if (attributes == nil) attributes = [[OFMutableArray alloc] init]; /* FIXME: Prevent having it twice! */ [attributes addObject: attr]; } - (void)addAttributeWithName: (OFString*)name_ stringValue: (OFString*)value { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; [self addAttribute: [OFXMLAttribute attributeWithName: name_ prefix: nil namespace: nil stringValue: value]]; [pool release]; } /* TODO: Replace attribute */ /* TODO: Remove attribute */ - (void)addChild: (OFXMLElement*)child { if (stringValue != nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if (children == nil) children = [[OFMutableArray alloc] init]; [children addObject: child]; } - (void)dealloc { [name release]; [attributes release]; [stringValue release]; [children release]; [super dealloc]; } @end @implementation OFString (OFXMLEscaping) |
︙ | ︙ |
Modified src/OFXMLParser.h from [28112670e4] to [608f055e14].
︙ | ︙ | |||
125 126 127 128 129 130 131 | OF_XMLPARSER_IN_COMMENT_4 } state; OFMutableString *cache; OFString *name; OFString *prefix; OFString *ns; OFMutableArray *attrs; | | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | OF_XMLPARSER_IN_COMMENT_4 } state; OFMutableString *cache; OFString *name; OFString *prefix; OFString *ns; OFMutableArray *attrs; OFString *attrName; OFString *attrPrefix; char delim; OFMutableArray *previous; } /** * \return A new, autoreleased OFXMLParser */ |
︙ | ︙ |
Modified src/OFXMLParser.m from [6ad29027d7] to [3568485abb].
︙ | ︙ | |||
107 108 109 110 111 112 113 | [delegate release]; [cache release]; [name release]; [prefix release]; [ns release]; [attrs release]; | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | [delegate release]; [cache release]; [name release]; [prefix release]; [ns release]; [attrs release]; [attrName release]; [attrPrefix release]; [previous release]; [super dealloc]; } - (id)delegate { |
︙ | ︙ | |||
355 356 357 358 359 360 361 | withLength: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; if ((tmp = memchr(cache_c, ':', cache_len)) != NULL ) { | | | | | | 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | withLength: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; if ((tmp = memchr(cache_c, ':', cache_len)) != NULL ) { attrName = [[OFString alloc] initWithCString: tmp + 1 length: cache_len - (tmp - cache_c) - 1]; attrPrefix = [[OFString alloc] initWithCString: cache_c length: tmp - cache_c]; } else { attrName = [cache copy]; attrPrefix = nil; } [cache setToCString: ""]; last = i + 1; state = OF_XMLPARSER_EXPECT_DELIM; } |
︙ | ︙ | |||
402 403 404 405 406 407 408 | if (attrs == nil) attrs = [[OFMutableArray alloc] init]; pool = [[OFAutoreleasePool alloc] init]; attr_val = [cache stringByXMLUnescapingWithHandler: self]; [attrs addObject: [OFXMLAttribute | | | | | | | 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | if (attrs == nil) attrs = [[OFMutableArray alloc] init]; pool = [[OFAutoreleasePool alloc] init]; attr_val = [cache stringByXMLUnescapingWithHandler: self]; [attrs addObject: [OFXMLAttribute attributeWithName: attrName prefix: attrPrefix namespace: nil stringValue: attr_val]]; [pool release]; [cache setToCString: ""]; [attrName release]; [attrPrefix release]; attrName = attrPrefix = nil; last = i + 1; state = OF_XMLPARSER_IN_TAG; } break; /* Expecting closing '>' */ |
︙ | ︙ | |||
508 509 510 511 512 513 514 | size_t i, last; BOOL in_entity; OFMutableString *ret; last = 0; in_entity = NO; ret = [OFMutableString string]; | | | 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | size_t i, last; BOOL in_entity; OFMutableString *ret; last = 0; in_entity = NO; ret = [OFMutableString string]; ((OFString*)ret)->isUTF8 = isUTF8; for (i = 0; i < length; i++) { if (!in_entity && string[i] == '&') { [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; last = i + 1; |
︙ | ︙ |