1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.4 KiB

//
// WRTStatusClient.m
// DDWRT-Monitor
//
// Created by Spike Grobstein on 5/30/11.
// Copyright 2011 Sadistech. All rights reserved.
//
#import "WRTStatusClient.h"
@implementation WRTStatusClient
- (id) initWithHostname:(NSString*)new_hostname port:(NSInteger*)new_port username:(NSString*)new_username password:(NSString*)new_password
{
self = [super init];
[self setHostname: new_hostname];
[self setPort: new_port];
[self setUsername: new_username];
[self setPassword: new_password];
return self;
}
#pragma mark -
- (NSMutableURLRequest*) buildRequest:(NSString*)uri
{
NSString *urlAddress = [NSString stringWithFormat:@"http://%@:%d/%@",
hostname,
port,
uri];
NSURL *url = [NSURL URLWithString:urlAddress];
//[self request:url]; // ---V
NSURLRequest *theRequest;
theRequest = [[NSMutableURLRequest alloc] initWithURL: url];
return [theRequest autorelease];
}
- (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface
{
NSString *endpoint = [NSString stringWithFormat:@"graph_if.svg?%@", interface];
return [self buildRequest:endpoint];
}
- (void) getStatusUpdate:(NSString*)uri delegate:(id)delegate
{
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:[self buildRequest: uri] delegate:delegate];
[theConnection autorelease];
// this function returns immediately
// the delegate will receive a function call with the following signature upon completion:
// - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
}
#pragma mark -
#pragma mark Accessors:
- (NSString*) getHostname
{
return hostname;
}
- (void) setHostname:(NSString*)new_hostname
{
NSString *old_hostname = hostname;
hostname = [new_hostname retain];
[old_hostname autorelease];
}
- (NSInteger*) getPort
{
return port;
}
- (void) setPort:(NSInteger*)new_port
{
port = new_port;
}
- (NSString*) getUsername
{
return username;
}
- (void) setUsername:(NSString*)new_username
{
NSString *old_username = username;
username = [new_username retain];
[old_username autorelease];
}
- (NSString*) getPassword
{
return password;
}
- (void) setPassword:(NSString*)new_password
{
NSString *old_password = password;
password = [new_password retain];
[old_password autorelease];
}
@end