Patch from brion to add an SSL option for StatusNet accounts. Fixes #13077.
2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AILaconicaAccount.h"
18 #import "AITwitterURLParser.h"
20 @implementation AILaconicaAccount
25 [adium.preferenceController registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
26 [NSNumber numberWithBool:YES], LACONICA_PREFERENCE_SSL, nil]
27 forGroup:LACONICA_PREF_GROUP
34 [self setLastDisconnectionError:AILocalizedString(@"No Host set", nil)];
42 * @brief Our default server if none is provided.
44 * Do not set a default server.
46 - (NSString *)defaultServer
54 * The API path extension for the given host.
58 // We need to guarantee this is an NSString, so -stringByAppendingPathComponent works.
59 NSString *path = [self preferenceForKey:LACONICA_PREFERENCE_PATH group:LACONICA_PREF_GROUP] ?: @"";
61 return [path stringByAppendingPathComponent:@"api"];
65 * @brief Our source token
67 * On Laconica, our given source token is "adium".
69 - (NSString *)sourceToken
75 * @brief Our explicit formatted UID
77 * This includes "additional necessary identifying information".
79 - (NSString *)explicitFormattedUID
82 return [NSString stringWithFormat:@"%@ (%@)", self.UID, self.host];
89 * @brief Use our host for the servername when storing password
91 - (BOOL)useHostForPasswordServerName
97 * @brief Not all StatusNet instances support HTTPS connections.
101 return [[self preferenceForKey:LACONICA_PREFERENCE_SSL group:LACONICA_PREF_GROUP] boolValue];
105 * @brief Laconica does not yet support OAuth.
113 * @brief Returns the link URL for a specific type of link
115 - (NSString *)addressForLinkType:(AITwitterLinkType)linkType
116 userID:(NSString *)userID
117 statusID:(NSString *)statusID
118 context:(NSString *)context
120 NSString *address = [super addressForLinkType:linkType userID:userID statusID:statusID context:context];
122 NSString *fullAddress = [self.host stringByAppendingPathComponent:[self preferenceForKey:LACONICA_PREFERENCE_PATH group:LACONICA_PREF_GROUP]];
124 NSString *protocol = self.useSSL ? @"https" : @"http";
126 if (linkType == AITwitterLinkStatus) {
127 address = [NSString stringWithFormat:@"%@://%@/notice/%@", protocol, fullAddress, statusID];
128 } else if (linkType == AITwitterLinkFriends) {
129 address = [NSString stringWithFormat:@"%@://%@/%@/subscriptions", protocol, fullAddress, userID];
130 } else if (linkType == AITwitterLinkFollowers) {
131 address = [NSString stringWithFormat:@"%@://%@/%@/subscribers", protocol, fullAddress, userID];
132 } else if (linkType == AITwitterLinkUserPage) {
133 address = [NSString stringWithFormat:@"%@://%@/%@", protocol, fullAddress, userID];
134 } else if (linkType == AITwitterLinkSearchHash) {
135 address = [NSString stringWithFormat:@"http://%@/tag/%@", fullAddress, context];
136 } else if (linkType == AITwitterLinkGroup) {
137 address = [NSString stringWithFormat:@"http://%@/group/%@", fullAddress, context];
144 * @brief Parse an attributed string into a linkified version.
146 - (NSAttributedString *)linkifiedAttributedStringFromString:(NSAttributedString *)inString
148 NSAttributedString *attributedString = [super linkifiedAttributedStringFromString:inString];
150 static NSCharacterSet *groupCharacters = nil;
152 if (!groupCharacters) {
153 NSMutableCharacterSet *disallowedCharacters = [[NSCharacterSet punctuationCharacterSet] mutableCopy];
154 [disallowedCharacters formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]];
156 groupCharacters = [[disallowedCharacters invertedSet] retain];
158 [disallowedCharacters release];
161 attributedString = [AITwitterURLParser linkifiedStringFromAttributedString:attributedString
162 forPrefixCharacter:@"!"
163 forLinkType:AITwitterLinkGroup
165 validCharacterSet:groupCharacters];
167 return attributedString;