My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
//
// ProxyURLProtocol.m
// PandoraBoy
//
// Created by Rob Napier on 11/30/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "ProxyURLProtocol.h"
#import <Foundation/NSURLProtocol.h>
#import "PlaylistURLProtocol.h"
#import "ArtworkURLProtocol.h"
#import "ResourceURLProtocol.h"
#import "StationsURLProtocol.h"
#import "FeedbackURLProtocol.h"

static NSString *PBProxyURLHeader = @"X-PB";

@implementation ProxyURLProtocol

// Accessors

- (NSURLConnection *)connection {
return [[_connection retain] autorelease];
}

- (void)setConnection:(NSURLConnection *)value {
if (_connection != value) {
[_connection release];
_connection = [value retain];
}
}

- (NSURLRequest *)request {
return [[_request retain] autorelease];
}

- (void)setRequest:(NSURLRequest *)value {
if (_request != value) {
[_request release];
_request = [value retain];
}
}

- (NSMutableData *)data {
return [[_data retain] autorelease];
}

- (void)appendData:(NSData *)newData {
if( _data == nil ) {
_data = [[NSMutableData alloc] initWithData:newData];
}
else
{
[_data appendData:newData];
}
}

// Class methods

+ (void)registerProxyProtocols {
[NSURLProtocol registerClass:[self class]];

[NSURLProtocol registerClass:[ResourceURLProtocol class]];
[NSURLProtocol registerClass:[StationsURLProtocol class]];
[NSURLProtocol registerClass:[FeedbackURLProtocol class]];
[NSURLProtocol registerClass:[PlaylistURLProtocol class]];
[NSURLProtocol registerClass:[ArtworkURLProtocol class]];
}

+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
if ( [[[request URL] scheme] isEqualToString:@"http"] &&
[request valueForHTTPHeaderField:PBProxyURLHeader] == nil )
{
return YES;
}
return NO;
}

+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
{
return request;
}

-(id)initWithRequest:(NSURLRequest *)request
cachedResponse:(NSCachedURLResponse *)cachedResponse
client:(id <NSURLProtocolClient>)client
{
// Modify request
NSMutableURLRequest *myRequest = [request mutableCopy];
[myRequest setValue:@"" forHTTPHeaderField:PBProxyURLHeader];

self = [super initWithRequest:myRequest
cachedResponse:cachedResponse
client:client];

if ( self ) {
[self setRequest:myRequest];
}
return self;
}

- (void)dealloc
{
[_request release];
[_connection release];
[_data release];
[super dealloc];
}

// Instance methods

- (void)startLoading
{
// use the regular URL donwload machinery to get the url contents
NSURLConnection *connection = [NSURLConnection connectionWithRequest:[self request]
delegate:self];
[self setConnection:connection];
}

-(void)stopLoading {
[[self connection] cancel];
}

// NSURLConnection delegates (generally we pass these on to our client)

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[[self client] URLProtocol:self didLoadData:data];
[self appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[[self client] URLProtocol:self didFailWithError:error];
[self setConnection:nil];
[_data release]; _data = nil;
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[[self client] URLProtocolDidFinishLoading:self];
[self setConnection:nil];
[_data release]; _data = nil;
}

-(NSString*)valueForParameter:(NSString*)parameter {
NSString *query = [[[self request] URL] query];

NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSEnumerator *e = [pairs objectEnumerator];
NSString *aKeyValue;
while( aKeyValue = [e nextObject] ) {
NSArray *split = [aKeyValue componentsSeparatedByString:@"="];
if( [[split objectAtIndex:0] isEqualToString:parameter] ) {
return [split objectAtIndex:1];
}
}
return nil;
}
@end
Show details Hide details

Change log

r146 by robnapier on Mar 07, 2009   Diff
 Issue 41 : Memory usage slowly increases
Go to: 

Older revisions

r92 by rintaw on Dec 10, 2007   Diff
Massive restructure to create
PlayerController
        (about half of Controller and
most of SongNotification).
Proper growling on play and pause.
...
r91 by rintaw on Dec 09, 2007   Diff
Stations menu includes "now playing"
icon
r89 by rintaw on Dec 08, 2007   Diff
Stations menu works with QuickMix.
All revisions of this file

File info

Size: 4323 bytes, 164 lines
Hosted by Google Code