~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to osx/WebClient.m

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This file is part of nzbget
 
3
 *
 
4
 *  Copyright (C) 2007-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 *
 
20
 * $Revision: 807 $
 
21
 * $Date: 2013-08-31 23:14:39 +0200 (Sat, 31 Aug 2013) $
 
22
 *
 
23
 */
 
24
 
 
25
#import <Cocoa/Cocoa.h>
 
26
#import "WebClient.h"
 
27
 
 
28
@implementation WebClient
 
29
 
 
30
- (id)initWithURLString:(NSString*)urlStr
 
31
                           receiver:(id)receiver
 
32
                                success:(SEL)successCallback
 
33
                                failure:(SEL)failureCallback {
 
34
        self = [super init];
 
35
        
 
36
        _receiver = receiver;
 
37
        _successCallback = successCallback;
 
38
        _failureCallback = failureCallback;
 
39
        NSURL *url = [NSURL URLWithString:urlStr];
 
40
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
 
41
        connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
 
42
        [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
 
43
 
 
44
        return self;
 
45
}
 
46
 
 
47
- (void) start {
 
48
        [connection start];
 
49
}
 
50
 
 
51
- (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSHTTPURLResponse *)aResponse {
 
52
        responseHeaderFields = [aResponse allHeaderFields];
 
53
        
 
54
        if ([aResponse statusCode] != 200)
 
55
        {
 
56
                failureCode = [aResponse statusCode];
 
57
                [connection cancel];
 
58
                [self failure];
 
59
                return;
 
60
        }
 
61
        
 
62
        NSInteger contentLength = [[responseHeaderFields objectForKey:@"Content-Length"] integerValue];
 
63
        if (contentLength > 0) {
 
64
                data = [[NSMutableData alloc] initWithCapacity:contentLength];
 
65
        } else {
 
66
                data = [[NSMutableData alloc] init];
 
67
        }
 
68
}
 
69
 
 
70
- (void)connection:(NSURLConnection *)aConnection didReceiveData:(NSData *)newData {
 
71
        [data appendData:newData];
 
72
}
 
73
 
 
74
- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection {
 
75
        [connection cancel];
 
76
        [self success];
 
77
}
 
78
 
 
79
- (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error {
 
80
        if ([[error domain] isEqual:NSURLErrorDomain])
 
81
        {
 
82
                failureCode = [error code];
 
83
        }
 
84
        
 
85
        [connection cancel];
 
86
        [self failure];
 
87
}
 
88
 
 
89
- (void)success {
 
90
        SuppressPerformSelectorLeakWarning([_receiver performSelector:_successCallback withObject:data];);
 
91
}
 
92
 
 
93
- (void)failure {
 
94
        SuppressPerformSelectorLeakWarning([_receiver performSelector:_failureCallback];);
 
95
}
 
96
 
 
97
@end