libpurple.framework 2.3.1 as before but with HAVE_OPENSSL defined, which enables...
[adiumx.git] / Source / AINulRemovalPlugin.m
blobf89a7f313200edad4c1f70e8f6588d2f338c162b
1 //
2 //  AINulRemovalPlugin.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 9/10/06.
6 //
8 #import "AINulRemovalPlugin.h"
9 #import <Adium/AIContentControllerProtocol.h>
10 #import <AIUtilities/AIAttributedStringAdditions.h>
12 @implementation AINulRemovalPlugin
14 - (void)installPlugin
16     //Register us as a filter
17         [[adium contentController] registerContentFilter:self ofType:AIFilterContent direction:AIFilterIncoming];
18         [[adium contentController] registerContentFilter:self ofType:AIFilterContent direction:AIFilterOutgoing];
21 - (void)uninstallPlugin
23         [[adium contentController] unregisterContentFilter:self];
26 - (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context
28         if (!inAttributedString || ![inAttributedString length]) return inAttributedString;
30         //Don't allow embedded NULs
31         static NSString *nulString = nil;
32         if (!nulString) {
33                 UInt8 bytes[1];
34                 bytes[0] = '\0';
35                 nulString = (NSString *)CFStringCreateWithBytes(kCFAllocatorDefault, bytes, 1, kCFStringEncodingASCII, false);
36         }
38         NSAttributedString *nulFreeAttributedString;
40         if ([[inAttributedString string] rangeOfString:nulString options:NSLiteralSearch].location != NSNotFound) {
41                 NSMutableAttributedString *temporaryString = [inAttributedString mutableCopy];
42                 [temporaryString replaceOccurrencesOfString:nulString
43                                                                                  withString:@""
44                                                                                         options:NSLiteralSearch
45                                                                                           range:NSMakeRange(0, [temporaryString length])];
46                 nulFreeAttributedString = [temporaryString autorelease];
48         } else {
49                 nulFreeAttributedString = inAttributedString;
50         }
52         return nulFreeAttributedString;
55 /*!
56  * @brief When should this filter run?
57  *
58  * Run this filter as early as possible to remove NULs in case other filters want to use the UTF8String of the filtered string.
59  */
60 - (float)filterPriority
62         return HIGHEST_FILTER_PRIORITY;
65 @end