mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
platform: ios: Remove FTP server as latest apple clang broke it
This commit is contained in:
@@ -16,7 +16,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "xash3d_types.h"
|
||||
#if XASH_SDL == 2
|
||||
#include <SDL.h> // SDL_GetBasePath
|
||||
#elif XASH_SDL == 3
|
||||
@@ -322,7 +321,7 @@ static qboolean FS_DetermineReadOnlyRootDirectory( char *out, size_t size )
|
||||
}
|
||||
|
||||
#if XASH_IOS
|
||||
Q_strncpy(out, IOS_GetExecDir(), size);
|
||||
Q_strncpy( out, IOS_GetExecDir(), size );
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,282 +0,0 @@
|
||||
//
|
||||
// AsyncSocket.h
|
||||
//
|
||||
// This class is in the public domain.
|
||||
// Originally created by Dustin Voss on Wed Jan 29 2003.
|
||||
// Updated and maintained by Deusty Designs and the Mac development community.
|
||||
//
|
||||
// http://code.google.com/p/cocoaasyncsocket/
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class AsyncSocket;
|
||||
@class AsyncReadPacket;
|
||||
@class AsyncWritePacket;
|
||||
|
||||
extern NSString *const AsyncSocketException;
|
||||
extern NSString *const AsyncSocketErrorDomain;
|
||||
|
||||
enum AsyncSocketError
|
||||
{
|
||||
AsyncSocketCFSocketError = kCFSocketError, // From CFSocketError enum.
|
||||
AsyncSocketNoError = 0, // Never used.
|
||||
AsyncSocketCanceledError, // onSocketWillConnect: returned NO.
|
||||
AsyncSocketReadMaxedOutError, // Reached set maxLength without completing
|
||||
AsyncSocketReadTimeoutError,
|
||||
AsyncSocketWriteTimeoutError
|
||||
};
|
||||
typedef enum AsyncSocketError AsyncSocketError;
|
||||
|
||||
@interface NSObject (AsyncSocketDelegate)
|
||||
|
||||
/**
|
||||
* In the event of an error, the socket is closed.
|
||||
* You may call "unreadData" during this call-back to get the last bit of data off the socket.
|
||||
* When connecting, this delegate method may be called
|
||||
* before"onSocket:didAcceptNewSocket:" or "onSocket:didConnectToHost:".
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err;
|
||||
|
||||
/**
|
||||
* Called when a socket disconnects with or without error. If you want to release a socket after it disconnects,
|
||||
* do so here. It is not safe to do that during "onSocket:willDisconnectWithError:".
|
||||
**/
|
||||
- (void)onSocketDidDisconnect:(AsyncSocket *)sock;
|
||||
|
||||
/**
|
||||
* Called when a socket accepts a connection. Another socket is spawned to handle it. The new socket will have
|
||||
* the same delegate and will call "onSocket:didConnectToHost:port:".
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
|
||||
|
||||
/**
|
||||
* Called when a new socket is spawned to handle a connection. This method should return the run-loop of the
|
||||
* thread on which the new socket and its delegate should operate. If omitted, [NSRunLoop currentRunLoop] is used.
|
||||
**/
|
||||
- (NSRunLoop *)onSocket:(AsyncSocket *)sock wantsRunLoopForNewSocket:(AsyncSocket *)newSocket;
|
||||
|
||||
/**
|
||||
* Called when a socket is about to connect. This method should return YES to continue, or NO to abort.
|
||||
* If aborted, will result in AsyncSocketCanceledError.
|
||||
*
|
||||
* If the connectToHost:onPort:error: method was called, the delegate will be able to access and configure the
|
||||
* CFReadStream and CFWriteStream as desired prior to connection.
|
||||
*
|
||||
* If the connectToAddress:error: method was called, the delegate will be able to access and configure the
|
||||
* CFSocket and CFSocketNativeHandle (BSD socket) as desired prior to connection. You will be able to access and
|
||||
* configure the CFReadStream and CFWriteStream in the onSocket:didConnectToHost:port: method.
|
||||
**/
|
||||
- (BOOL)onSocketWillConnect:(AsyncSocket *)sock;
|
||||
|
||||
|
||||
/**
|
||||
* Called when a read stream is closed. This method should return YES, if you
|
||||
* want to close the socket of the stream, or NO then the socket won't be closed.
|
||||
* This was added for the workaround to solve the issue of firefox and os-x finder,
|
||||
* which seem to close a read stream for ftp's list command.
|
||||
* 'iosftpserver' returns YES only when the socket is for FTP::STORE command.
|
||||
**/
|
||||
- (BOOL)onReadStreamEnded:(AsyncSocket *)sock;
|
||||
|
||||
/**
|
||||
* Called when a socket connects and is ready for reading and writing.
|
||||
* The host parameter will be an IP address, not a DNS name.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port;
|
||||
|
||||
/**
|
||||
* Called when a socket has completed reading the requested data into memory.
|
||||
* Not called if there is an error.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called when a socket has read in data, but has not yet completed the read.
|
||||
* This would occur if using readToData: or readToLength: methods.
|
||||
* It may be used to for things such as updating progress bars.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didReadPartialDataOfLength:(CFIndex)partialLength tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called when a socket has completed writing the requested data. Not called if there is an error.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag;
|
||||
|
||||
@end
|
||||
|
||||
@interface AsyncSocket : NSObject
|
||||
{
|
||||
CFSocketRef theSocket; // IPv4 accept or connect socket
|
||||
CFSocketRef theSocket6; // IPv6 accept or connect socket
|
||||
CFReadStreamRef theReadStream;
|
||||
CFWriteStreamRef theWriteStream;
|
||||
|
||||
CFRunLoopSourceRef theSource; // For theSocket
|
||||
CFRunLoopSourceRef theSource6; // For theSocket6
|
||||
CFRunLoopRef theRunLoop;
|
||||
CFSocketContext theContext;
|
||||
|
||||
NSMutableArray *theReadQueue;
|
||||
AsyncReadPacket *theCurrentRead;
|
||||
NSTimer *theReadTimer;
|
||||
NSMutableData *partialReadBuffer;
|
||||
|
||||
NSMutableArray *theWriteQueue;
|
||||
AsyncWritePacket *theCurrentWrite;
|
||||
NSTimer *theWriteTimer;
|
||||
|
||||
id theDelegate;
|
||||
Byte theFlags;
|
||||
|
||||
long theUserData;
|
||||
}
|
||||
|
||||
- (id)init;
|
||||
- (id)initWithDelegate:(id)delegate;
|
||||
- (id)initWithDelegate:(id)delegate userData:(long)userData;
|
||||
|
||||
/* String representation is long but has no "\n". */
|
||||
- (NSString *)description;
|
||||
|
||||
/**
|
||||
* Use "canSafelySetDelegate" to see if there is any pending business (reads and writes) with the current delegate
|
||||
* before changing it. It is, of course, safe to change the delegate before connecting or accepting connections.
|
||||
**/
|
||||
- (id)delegate;
|
||||
- (BOOL)canSafelySetDelegate;
|
||||
- (void)setDelegate:(id)delegate;
|
||||
|
||||
/* User data can be a long, or an id or void * cast to a long. */
|
||||
- (long)userData;
|
||||
- (void)setUserData:(long)userData;
|
||||
|
||||
/* Don't use these to read or write. And don't close them, either! */
|
||||
- (CFSocketRef)getCFSocket;
|
||||
- (CFReadStreamRef)getCFReadStream;
|
||||
- (CFWriteStreamRef)getCFWriteStream;
|
||||
|
||||
/**
|
||||
* Once one of these methods is called, the AsyncSocket instance is locked in, and the rest can't be called without
|
||||
* disconnecting the socket first. If the attempt times out or fails, these methods either return NO or
|
||||
* call "onSocket:willDisconnectWithError:" and "onSockedDidDisconnect:".
|
||||
**/
|
||||
- (BOOL)acceptOnPort:(UInt16)port error:(NSError **)errPtr;
|
||||
- (BOOL)acceptOnAddress:(NSString *)hostaddr port:(UInt16)port error:(NSError **)errPtr;
|
||||
- (BOOL)connectToHost:(NSString *)hostname onPort:(UInt16)port error:(NSError **)errPtr;
|
||||
- (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Disconnects immediately. Any pending reads or writes are dropped.
|
||||
**/
|
||||
- (void)disconnect;
|
||||
|
||||
/**
|
||||
* Disconnects after all pending writes have completed.
|
||||
* After calling this, the read and write methods (including "readDataWithTimeout:tag:") will do nothing.
|
||||
* The socket will disconnect even if there are still pending reads.
|
||||
**/
|
||||
- (void)disconnectAfterWriting;
|
||||
|
||||
/* Returns YES if the socket and streams are open, connected, and ready for reading and writing. */
|
||||
- (BOOL)isConnected;
|
||||
|
||||
/**
|
||||
* Returns the local or remote host and port to which this socket is connected, or nil and 0 if not connected.
|
||||
* The host will be an IP address.
|
||||
**/
|
||||
- (NSString *)connectedHost;
|
||||
- (UInt16)connectedPort;
|
||||
|
||||
- (NSString *)localHost;
|
||||
- (UInt16)localPort;
|
||||
|
||||
- (BOOL)isIPv4;
|
||||
- (BOOL)isIPv6;
|
||||
|
||||
// The readData and writeData methods won't block. To not time out, use a negative time interval.
|
||||
// If they time out, "onSocket:disconnectWithError:" is called. The tag is for your convenience.
|
||||
// You can use it as an array index, step number, state id, pointer, etc., just like the socket's user data.
|
||||
|
||||
/**
|
||||
* This will read a certain number of bytes into memory, and call the delegate method when those bytes have been read.
|
||||
* If there is an error, partially read data is lost.
|
||||
* If the length is 0, this method does nothing and the delegate is not called.
|
||||
**/
|
||||
- (void)readDataToLength:(CFIndex)length withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* This reads bytes until (and including) the passed "data" parameter, which acts as a separator.
|
||||
* The bytes and the separator are returned by the delegate method.
|
||||
*
|
||||
* If you pass nil or zero-length data as the "data" parameter,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
|
||||
* Note that this method is not character-set aware, so if a separator can occur naturally as part of the encoding for
|
||||
* a character, the read will prematurely end.
|
||||
**/
|
||||
- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Same as readDataToData:withTimeout:tag, with the additional restriction that the amount of data read
|
||||
* may not surpass the given maxLength (specified in bytes).
|
||||
*
|
||||
* If you pass a maxLength parameter that is less than the length of the data parameter,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* If the max length is surpassed, it is treated the same as a timeout - the socket is closed.
|
||||
*
|
||||
* Pass -1 as maxLength if no length restriction is desired, or simply use the readDataToData:withTimeout:tag method.
|
||||
**/
|
||||
- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout maxLength:(CFIndex)length tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads the first available bytes that become available on the socket.
|
||||
**/
|
||||
- (void)readDataWithTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/* Writes data to the socket, and calls the delegate when finished.
|
||||
*
|
||||
* If you pass in nil or zero-length data, this method does nothing and the delegate will not be called.
|
||||
**/
|
||||
- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Returns progress of current read or write, from 0.0 to 1.0, or NaN if no read/write (use isnan() to check).
|
||||
* "tag", "done" and "total" will be filled in if they aren't NULL.
|
||||
**/
|
||||
- (float)progressOfReadReturningTag:(long *)tag bytesDone:(CFIndex *)done total:(CFIndex *)total;
|
||||
- (float)progressOfWriteReturningTag:(long *)tag bytesDone:(CFIndex *)done total:(CFIndex *)total;
|
||||
|
||||
/**
|
||||
* For handling readDataToData requests, data is necessarily read from the socket in small increments.
|
||||
* The performance can be improved by allowing AsyncSocket to read larger chunks at a time and
|
||||
* store any overflow in a small internal buffer.
|
||||
* This is termed pre-buffering, as some data may be read for you before you ask for it.
|
||||
* If you use readDataToData a lot, enabling pre-buffering may offer a small performance improvement.
|
||||
*
|
||||
* Pre-buffering is disabled by default. You must explicitly enable it to turn it on.
|
||||
*
|
||||
* Note: If your protocol negotiates upgrades to TLS (as opposed to using TLS from the start), you should
|
||||
* consider how, if at all, pre-buffering could affect the TLS negotiation sequence.
|
||||
* This is because TLS runs atop TCP, and requires sending/receiving a TLS handshake over the TCP socket.
|
||||
* If the negotiation sequence is poorly designed, pre-buffering could potentially pre-read part of the TLS handshake,
|
||||
* thus causing TLS to fail. In almost all cases, especially when implementing a formalized protocol, this will never
|
||||
* be a hazard.
|
||||
**/
|
||||
- (void)enablePreBuffering;
|
||||
|
||||
/**
|
||||
* In the event of an error, this method may be called during onSocket:willDisconnectWithError: to read
|
||||
* any data that's left on the socket.
|
||||
**/
|
||||
- (NSData *)unreadData;
|
||||
|
||||
/* A few common line separators, for use with "readDataToData:withTimeout:tag:". */
|
||||
+ (NSData *)CRLFData; // 0x0D0A
|
||||
+ (NSData *)CRData; // 0x0D
|
||||
+ (NSData *)LFData; // 0x0A
|
||||
+ (NSData *)ZeroData; // 0x00
|
||||
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "AsyncSocket.h"
|
||||
|
||||
#import "FtpDataConnection.h"
|
||||
#import "FtpDefines.h"
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
@class FtpServer;
|
||||
|
||||
@interface FtpConnection : NSObject {
|
||||
AsyncSocket *connectionSocket; // Socket for this particular connection
|
||||
FtpServer *server; // pointer to Server object
|
||||
|
||||
AsyncSocket *dataListeningSocket; // Socket to listen for a data connection to spawn on <-- think this is now redundant
|
||||
AsyncSocket *dataSocket; // duplicates the listening socket - remove listening socket from code when working - which seems to be the case.
|
||||
|
||||
FtpDataConnection *dataConnection; // instance handling spawned data connection socket
|
||||
|
||||
NSArray *msgComponents; // The Message rcvd broken into an array
|
||||
UInt16 dataPort;
|
||||
int transferMode;
|
||||
NSMutableArray *queuedData;
|
||||
|
||||
NSString *currentUser; // The current user for this connection
|
||||
NSString *currentDir; // The current directory for this connection
|
||||
NSString *currentFile; // File that is about to be uploaded
|
||||
NSFileHandle *currentFileHandle; // File handle of what to save
|
||||
|
||||
NSString *rnfrFilename; // rnfr
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(id)initWithAsyncSocket:(AsyncSocket*)newSocket forServer:(id)myServer ;
|
||||
#pragma mark STATE
|
||||
|
||||
@property(readwrite)int transferMode;
|
||||
|
||||
@property(readwrite, retain ) NSString *currentFile;
|
||||
@property(readwrite, retain ) NSString *currentDir;
|
||||
@property(readwrite, retain ) NSString *rnfrFilename;
|
||||
|
||||
-(NSString*)connectionAddress;
|
||||
|
||||
|
||||
#pragma mark ASYNCSOCKET DATACONN
|
||||
|
||||
-(BOOL)openDataSocket:(int)portNumber;
|
||||
-(int)choosePasvDataPort;
|
||||
|
||||
|
||||
-(BOOL)onSocketWillConnect:(AsyncSocket *)sock;
|
||||
-(void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
|
||||
|
||||
#pragma mark ASYNCSOCKET FTPCLIENT CONNECTION
|
||||
-(void)onSocket:(AsyncSocket*)sock didReadData:(NSData*)data withTag:(long)tag;
|
||||
-(void)onSocket:(AsyncSocket*)sock didWriteDataWithTag:(long)tag;
|
||||
-(void)sendMessage:(NSString*)ftpMessage; // calls FC writedata
|
||||
-(void)sendDataString:(NSString*)dataString; // calls FDC writedata
|
||||
-(void)sendData:(NSMutableData*)data;
|
||||
-(void)didReceiveDataWritten; // notification that FDC wrote data
|
||||
-(void)didReceiveDataRead; // notification that FDC read data ie a transfer
|
||||
-(void)didFinishReading; // Called at the closing == end of a data connection from the client we presume
|
||||
|
||||
#pragma mark PROCESS
|
||||
|
||||
-(void)processDataRead:(NSData*)data;
|
||||
-(void)processCommand;
|
||||
|
||||
#pragma mark COMMANDS
|
||||
-(void)doQuit:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doUser:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doPass:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doStat:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doFeat:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doList:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doPwd:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doNoop:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doSyst:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doLprt:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doPasv:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doEpsv:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doPort:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doNlst:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doStor:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doRetr:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doDele:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doMlst:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doSize:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doMkdir:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doCdUp:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doRnfr:(id)sender arguments:(NSArray*)arguments;
|
||||
-(void)doRnto:(id)sender arguments:(NSArray*)arguments;
|
||||
|
||||
#pragma mark UTITILITES
|
||||
-(NSString*)makeFilePathFrom:(NSString*)filename;
|
||||
-(unsigned long long)fileSize:(NSString*)filePath;
|
||||
-(NSString*)fileNameFromArgs:(NSArray*)arguments;
|
||||
- (Boolean)changedCurrentDirectoryTo:(NSString *)newDirectory;
|
||||
-(Boolean)canChangeDirectoryTo:(NSString *)testDirectory;
|
||||
- (Boolean)accessibleFilePath:(NSString*)filePath; // check filepath exists and is in basedir ( if set )
|
||||
- (Boolean)validNewFilePath:(NSString*)filePath;
|
||||
- (NSString *)visibleCurrentDir;
|
||||
-(NSString *)rootedPath:(NSString*)path;
|
||||
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AsyncSocket.h"
|
||||
#import "FtpDefines.h"
|
||||
|
||||
@class FtpConnection;
|
||||
|
||||
@interface FtpDataConnection : NSObject {
|
||||
AsyncSocket *dataSocket;
|
||||
FtpConnection *ftpConnection; // connection which generated data socket we are tied to
|
||||
|
||||
AsyncSocket *dataListeningSocket;
|
||||
id dataConnection;
|
||||
NSMutableData *receivedData;
|
||||
int connectionState;
|
||||
|
||||
}
|
||||
-(id)initWithAsyncSocket:(AsyncSocket*)newSocket forConnection:(id)aConnection withQueuedData:(NSMutableArray*)queuedData;
|
||||
-(void)writeString:(NSString*)dataString;
|
||||
-(void)writeData:(NSMutableData*)data;
|
||||
-(void)writeQueuedData:(NSMutableArray*)queuedData;
|
||||
-(void)closeConnection;
|
||||
|
||||
#pragma mark ASYNCSOCKET DELEGATES
|
||||
-(BOOL)onSocketWillConnect:(AsyncSocket *)sock;
|
||||
-(void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
|
||||
-(void)onSocket:(AsyncSocket*)sock didReadData:(NSData*)data withTag:(long)tag;
|
||||
-(void)onSocket:(AsyncSocket*)sock didWriteDataWithTag:(long)tag;
|
||||
|
||||
-(void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err;
|
||||
|
||||
@property (readonly) NSMutableData *receivedData;
|
||||
@property (readwrite) int connectionState;
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import "FtpDataConnection.h"
|
||||
#import "FtpConnection.h"
|
||||
|
||||
|
||||
@implementation FtpDataConnection
|
||||
|
||||
@synthesize receivedData;
|
||||
@synthesize connectionState;
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(id)initWithAsyncSocket:(AsyncSocket*)newSocket forConnection:(id)aConnection withQueuedData:(NSMutableArray*)queuedData
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
self = [super init ];
|
||||
if (self)
|
||||
{
|
||||
dataSocket = [newSocket retain ]; // Hang onto the socket that was generated - the FDC is retained by FC
|
||||
ftpConnection = aConnection;
|
||||
|
||||
[ dataSocket setDelegate:self ];
|
||||
|
||||
if ( [queuedData count ] )
|
||||
{
|
||||
NSLog(@"FC:Write Queued Data");
|
||||
[self writeQueuedData:queuedData ];
|
||||
[ queuedData removeAllObjects ]; // Clear out queue
|
||||
}
|
||||
// [ dataSocket readDataToData:[AsyncSocket CRLFData] withTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
[ dataSocket readDataWithTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
dataListeningSocket = nil;
|
||||
receivedData = nil; // [[ NSMutableData alloc ] init ] 12/nov/08 - no need for this. rcd is just a pointer
|
||||
|
||||
connectionState = clientQuiet; // Nothing coming through
|
||||
}
|
||||
return self;
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)dealloc
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
[dataSocket release];
|
||||
[dataListeningSocket release];
|
||||
[dataConnection release];
|
||||
// [receivedData release];
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)writeString:(NSString*)dataString
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FDC:writeStringData");
|
||||
|
||||
NSMutableData *data = [[ dataString dataUsingEncoding:NSUTF8StringEncoding ] mutableCopy]; // Autoreleased
|
||||
[ data appendData:[AsyncSocket CRLFData] ];
|
||||
|
||||
[ dataSocket writeData:data withTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
[ dataSocket readDataWithTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)writeData:(NSMutableData*)data
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FDC:writeData");
|
||||
// [ data appendData:[AsyncSocket CRLFData] ]; // Add on CRLF to end of data - as Windows Explorer needs it
|
||||
|
||||
connectionState = clientReceiving; // We hope
|
||||
|
||||
[ dataSocket writeData:data withTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
|
||||
[ dataSocket readDataWithTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)writeQueuedData:(NSMutableArray*)queuedData
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
for (NSMutableData* data in queuedData) {
|
||||
[self writeData:data ];
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)closeConnection
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FDC:closeConnection");
|
||||
[ dataSocket disconnect ];
|
||||
|
||||
}
|
||||
#pragma mark ASYNCSOCKET DELEGATES
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(BOOL)onSocketWillConnect:(AsyncSocket *)sock
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
NSLog(@"FDC:onSocketWillConnect");
|
||||
[ dataSocket readDataWithTimeout:READ_TIMEOUT tag:0 ];
|
||||
return YES;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
// This shouldnt happen - we should be connected already - and havent set up a listening socket
|
||||
NSLog(@"FDC:New Connection -- shouldn't be called");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)onSocket:(AsyncSocket*)sock didReadData:(NSData*)data withTag:(long)tag
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FDC:didReadData");
|
||||
|
||||
// [ dataSocket readDataToData:[AsyncSocket CRLFData] withTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ]; // continue reading
|
||||
[ dataSocket readDataWithTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
|
||||
NSMutableData *mutdata = [data mutableCopy];
|
||||
receivedData = [ mutdata retain]; // make autoreleased copy of data
|
||||
|
||||
// notify connection data came through, ( will write data for us )
|
||||
[ftpConnection didReceiveDataRead ]; // notify, the connection, so it knows to write the data
|
||||
[ receivedData release ]; // let go, not our business anymore
|
||||
connectionState = clientSent;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)onSocket:(AsyncSocket*)sock didWriteDataWithTag:(long)tag
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FDC:didWriteData");
|
||||
[ ftpConnection didReceiveDataWritten ]; // notify that we are finished writing
|
||||
|
||||
// [ dataSocket readDataToData:[AsyncSocket CRLFData] withTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ]; // continue reading
|
||||
[ dataSocket readDataWithTimeout:READ_TIMEOUT tag:FTP_CLIENT_REQUEST ];
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FDC:willDisconnect");
|
||||
// if we were writing and there's no error, then it must be the end of file
|
||||
|
||||
if ( connectionState == clientSending )
|
||||
{
|
||||
NSLog(@"FDC::did FinishReading");
|
||||
// hopefully this is the end of the connection. not sure how we can tell
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"FDC: we werent expecting this as we never set clientSending prob late coming up");
|
||||
}
|
||||
[ ftpConnection didFinishReading ]; // its over, please send the message
|
||||
}
|
||||
|
||||
- (BOOL)onReadStreamEnded:(AsyncSocket*)sock
|
||||
{
|
||||
NSLog( @"FDC: onReadStreamEnded %d(clientSending is %d)", connectionState, clientSending );
|
||||
if ( connectionState == clientSent ||
|
||||
connectionState == clientSending ) return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,15 +0,0 @@
|
||||
enum {
|
||||
pasvftp=0,epsvftp,portftp,lprtftp, eprtftp
|
||||
};
|
||||
|
||||
#define DATASTR(args) [ args dataUsingEncoding:NSUTF8StringEncoding ]
|
||||
|
||||
#define SERVER_PORT 20000
|
||||
#define READ_TIMEOUT -1
|
||||
|
||||
#define FTP_CLIENT_REQUEST 0
|
||||
|
||||
enum {
|
||||
|
||||
clientSending=0, clientReceiving=1, clientQuiet=2,clientSent=3
|
||||
};
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
#import "AsyncSocket.h"
|
||||
#import "FtpDefines.h"
|
||||
#import "FtpConnection.h"
|
||||
#import "list.h"
|
||||
|
||||
@interface FtpServer : NSObject {
|
||||
|
||||
AsyncSocket *listenSocket;
|
||||
NSMutableArray *connectedSockets;
|
||||
id server;
|
||||
id notificationObject;
|
||||
|
||||
int portNumber;
|
||||
id delegate;
|
||||
|
||||
NSMutableArray *connections;
|
||||
|
||||
NSDictionary *commands;
|
||||
NSString *baseDir;
|
||||
Boolean changeRoot; // Change root to virtual root ( basedir )
|
||||
int clientEncoding; // FTP client encoding type
|
||||
}
|
||||
- (id)initWithPort:(unsigned)serverPort withDir:(NSString *)aDirectory notifyObject:(id)sender;
|
||||
- (void)stopFtpServer;
|
||||
|
||||
#pragma mark ASYNCSOCKET DELEGATES
|
||||
- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
|
||||
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port;
|
||||
|
||||
#pragma mark NOTIFICATIONS
|
||||
- (void)didReceiveFileListChanged;
|
||||
|
||||
#pragma mark CONNECTIONS
|
||||
- (void)closeConnection:(id)theConnection;
|
||||
- (NSString *)createList:(NSString *)directoryPath;
|
||||
|
||||
@property (readwrite, retain) AsyncSocket *listenSocket;
|
||||
@property (readwrite, retain) NSMutableArray *connectedSockets;
|
||||
@property (readwrite, retain) id server;
|
||||
@property (readwrite, retain) id notificationObject;
|
||||
@property (readwrite) int portNumber;
|
||||
@property (readwrite, retain) id delegate;
|
||||
@property (readwrite, retain) NSMutableArray *connections;
|
||||
@property (readwrite, retain) NSDictionary *commands;
|
||||
@property (readwrite, retain) NSString *baseDir;
|
||||
@property (readwrite) Boolean changeRoot;
|
||||
@property (readwrite) int clientEncoding;
|
||||
|
||||
@end
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
// 11/02/08 changes to made to allow stopping of the server. Also added a bit of code to show users IP address.
|
||||
// Cleaned up the code to make the retains and releases a bit more obvious... mostly programming style preferences.
|
||||
// Added a stop Ftp server method to be called from where ever it was start. See iphoneLibTestViewController.m to see how I was calling it.
|
||||
// Most users wouldn't want the server to continue to run once the transfers are done.
|
||||
|
||||
|
||||
#import "FtpServer.h"
|
||||
|
||||
@implementation FtpServer
|
||||
|
||||
@synthesize listenSocket, connectedSockets, server, notificationObject, portNumber, delegate, commands, baseDir, connections;
|
||||
|
||||
@synthesize clientEncoding;
|
||||
@synthesize changeRoot;
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
- (id)initWithPort:(unsigned)serverPort withDir:(NSString*)aDirectory notifyObject:(id)sender
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if( self = [super init] ) {
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
self.notificationObject = sender;
|
||||
|
||||
// Load up commands
|
||||
NSString *plistPath = [[ NSBundle mainBundle ] pathForResource:@"ftp_commands" ofType:@"plist"];
|
||||
if ( ! [ [ NSFileManager defaultManager ] fileExistsAtPath:plistPath ] )
|
||||
{
|
||||
NSLog(@"ftp_commands.plist missing");
|
||||
}
|
||||
commands = [ [ NSDictionary alloc ] initWithContentsOfFile:plistPath];
|
||||
|
||||
// Clear out connections list
|
||||
NSMutableArray *myConnections = [[NSMutableArray alloc] init];
|
||||
self.connections = myConnections;
|
||||
[myConnections release];
|
||||
|
||||
|
||||
|
||||
// Create a socket
|
||||
self.portNumber = serverPort;
|
||||
|
||||
AsyncSocket *myListenSocket = [[AsyncSocket alloc] initWithDelegate:self];
|
||||
self.listenSocket = myListenSocket;
|
||||
[myListenSocket release];
|
||||
|
||||
NSLog(@"Listening on %u", portNumber);
|
||||
[listenSocket acceptOnPort:serverPort error:&error]; // start lisetning on this port.
|
||||
|
||||
NSMutableArray *myConnectedSockets = [[NSMutableArray alloc] initWithCapacity:1];
|
||||
self.connectedSockets = myConnectedSockets;
|
||||
[myConnectedSockets release];
|
||||
|
||||
// Set directory - have to do this because on iphone, some directories arent what they report back as, so need real path it resolves to, CHECKME - might be an easier way
|
||||
NSFileManager *fileManager = [ NSFileManager defaultManager ];
|
||||
NSString *expandedPath = [ aDirectory stringByStandardizingPath ];
|
||||
|
||||
// CHANGE TO NEW DIRECTORY & GET SYSTEM FILE PATH ( no .. etc )
|
||||
if ([ fileManager changeCurrentDirectoryPath:expandedPath ]) // try changing to directory
|
||||
{
|
||||
|
||||
self.baseDir = [[ fileManager currentDirectoryPath ] copy] ; // Gets the real path. CHECKME.
|
||||
// self.baseDir = @"/Users"; // REMOVEME - added for testing 7/6/10
|
||||
}
|
||||
else
|
||||
{
|
||||
self.baseDir = aDirectory; // shouldnt get to this line really
|
||||
}
|
||||
|
||||
self.changeRoot = false; // true if you want them to be sandboxed/chrooted into the basedir
|
||||
|
||||
// the default client encoding is UTF8
|
||||
self.clientEncoding = NSUTF8StringEncoding;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)stopFtpServer
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if(listenSocket)[listenSocket disconnect];
|
||||
[connectedSockets removeAllObjects];
|
||||
|
||||
[connections removeAllObjects];
|
||||
|
||||
}
|
||||
#pragma mark ASYNCSOCKET DELEGATES
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
FtpConnection *newConnection = [[[ FtpConnection alloc ] initWithAsyncSocket:newSocket forServer:self] autorelease]; // Create an ftp connection
|
||||
|
||||
|
||||
|
||||
|
||||
[ connections addObject:newConnection ]; // Add this to our list of connections
|
||||
|
||||
NSLog(@"FS:didAcceptNewSocket port:%i", [sock localPort]);
|
||||
|
||||
if ([sock localPort] == portNumber )
|
||||
{
|
||||
NSLog(@"Connection on Server Port");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// must be a data comms port
|
||||
// spawn a data comms port
|
||||
// look for the connection with the same port
|
||||
// and attach it
|
||||
NSLog(@"--ERROR %i, %i", [sock localPort],portNumber);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSLog(@"FtpServer:didConnectToHost port:%i", [sock localPort]);
|
||||
}
|
||||
|
||||
#pragma mark NOTIFICATIONS
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(void)didReceiveFileListChanged
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if ([notificationObject respondsToSelector:@selector(didReceiveFileListChanged)])
|
||||
[notificationObject didReceiveFileListChanged ];
|
||||
}
|
||||
#pragma mark CONNECTIONS
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
- (void)closeConnection:(id)theConnection
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
// Search through connections for this one - and delete
|
||||
// this should release it - and delloc
|
||||
|
||||
[connections removeObject:theConnection ];
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
-(NSString*)createList:(NSString*)directoryPath
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
return createList(directoryPath);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
- (void)dealloc
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
|
||||
if(listenSocket)
|
||||
{
|
||||
[listenSocket disconnect];
|
||||
[listenSocket release];
|
||||
}
|
||||
|
||||
[connectedSockets release];
|
||||
[notificationObject release];
|
||||
[connections release];
|
||||
[commands release];
|
||||
[baseDir release];
|
||||
[super dealloc];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// networkController.h
|
||||
// DiddyDJ
|
||||
//
|
||||
// Created by Richard Dearlove on 21/10/2008.
|
||||
// Copyright 2008 DiddySoft. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <SystemConfiguration/SystemConfiguration.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
@interface NetworkController : NSObject {
|
||||
|
||||
}
|
||||
+ (NSString *)localWifiIPAddress;
|
||||
+ (NSString *) localIPAddress;
|
||||
+ (BOOL)addressFromString:(NSString *)IPAddress address:(struct sockaddr_in *)address;
|
||||
+ (NSString *) getIPAddressForHost: (NSString *) theHost;
|
||||
+ (BOOL) hostAvailable: (NSString *) theHost;
|
||||
+ (BOOL) connectedToNetwork;
|
||||
@end
|
||||
@@ -1,184 +0,0 @@
|
||||
//
|
||||
// networkController.m
|
||||
//
|
||||
// Created by Richard Dearlove on 21/10/2008.
|
||||
// Copyright 2008 DiddySoft. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NetworkController.h"
|
||||
|
||||
@implementation NetworkController
|
||||
|
||||
// Return the localized IP address
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
+ (NSString *)localWifiIPAddress
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
{
|
||||
NSString *address = @"error";
|
||||
struct ifaddrs *interfaces = NULL;
|
||||
struct ifaddrs *temp_addr = NULL;
|
||||
int success = 0;
|
||||
|
||||
// retrieve the current interfaces - returns 0 on success
|
||||
success = getifaddrs(&interfaces);
|
||||
if (success == 0)
|
||||
{
|
||||
// Loop through linked list of interfaces
|
||||
temp_addr = interfaces;
|
||||
while(temp_addr != NULL)
|
||||
{
|
||||
if(temp_addr->ifa_addr->sa_family == AF_INET)
|
||||
{
|
||||
// Check if interface is en0 which is the wifi connection on the iPhone
|
||||
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
|
||||
{
|
||||
// Get NSString from C String
|
||||
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
|
||||
}
|
||||
}
|
||||
|
||||
temp_addr = temp_addr->ifa_next;
|
||||
}
|
||||
}
|
||||
|
||||
// Free memory
|
||||
freeifaddrs(interfaces);
|
||||
|
||||
return address;
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
+ (NSString *) localIPAddress
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
char baseHostName[255];
|
||||
gethostname(baseHostName, 255);
|
||||
|
||||
// Adjust for iPhone -- add .local to the host name
|
||||
char hn[255];
|
||||
sprintf(hn, "%s.local", baseHostName);
|
||||
|
||||
struct hostent *host = gethostbyname(hn);
|
||||
if (host == NULL)
|
||||
{
|
||||
herror("resolv");
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
struct in_addr **list = (struct in_addr **)host->h_addr_list;
|
||||
return [NSString stringWithCString:inet_ntoa(*list[0])];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
+ (BOOL)addressFromString:(NSString *)IPAddress address:(struct sockaddr_in *)address
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!IPAddress || ![IPAddress length]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
memset((char *) address, sizeof(struct sockaddr_in), 0);
|
||||
address->sin_family = AF_INET;
|
||||
address->sin_len = sizeof(struct sockaddr_in);
|
||||
|
||||
int conversionResult = inet_aton([IPAddress UTF8String], &address->sin_addr);
|
||||
if (conversionResult == 0) {
|
||||
NSAssert1(conversionResult != 1, @"Failed to convert the IP address string into a sockaddr_in: %@", IPAddress);
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
+ (NSString *) getIPAddressForHost: (NSString *) theHost
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
struct hostent *host = gethostbyname([theHost UTF8String]);
|
||||
|
||||
if (host == NULL) {
|
||||
herror("resolv");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct in_addr **list = (struct in_addr **)host->h_addr_list;
|
||||
NSString *addressString = [NSString stringWithCString:inet_ntoa(*list[0])];
|
||||
return addressString;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
+ (BOOL) hostAvailable: (NSString *) theHost
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
NSString *addressString = [self getIPAddressForHost:theHost];
|
||||
if (!addressString)
|
||||
{
|
||||
printf("Error recovering IP address from host name\n");
|
||||
return NO;
|
||||
}
|
||||
|
||||
struct sockaddr_in address;
|
||||
BOOL gotAddress = [self addressFromString:addressString address:&address];
|
||||
|
||||
if (!gotAddress)
|
||||
{
|
||||
printf("Error recovering sockaddr address from %s\n", [addressString UTF8String]);
|
||||
return NO;
|
||||
}
|
||||
|
||||
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&address);
|
||||
SCNetworkReachabilityFlags flags;
|
||||
|
||||
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
|
||||
CFRelease(defaultRouteReachability);
|
||||
|
||||
if (!didRetrieveFlags)
|
||||
{
|
||||
printf("Error. Could not recover network reachability flags\n");
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL isReachable = flags & kSCNetworkFlagsReachable;
|
||||
return isReachable ? YES : NO;;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
+ (BOOL) connectedToNetwork
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
// Create zero addy
|
||||
struct sockaddr_in zeroAddress;
|
||||
bzero(&zeroAddress, sizeof(zeroAddress));
|
||||
zeroAddress.sin_len = sizeof(zeroAddress);
|
||||
zeroAddress.sin_family = AF_INET;
|
||||
|
||||
// Recover reachability flags
|
||||
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
|
||||
CFRelease(defaultRouteReachability);
|
||||
|
||||
SCNetworkReachabilityFlags flags;
|
||||
|
||||
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
|
||||
if (!didRetrieveFlags)
|
||||
{
|
||||
printf("Error. Could not recover network reachability flags\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL isReachable = flags & kSCNetworkFlagsReachable;
|
||||
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
|
||||
// BOOL isEDGE = flags & kSCNetworkReachabilityFlagsIsWWAN;
|
||||
return (isReachable && !needsConnection) ? YES : NO;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>ack</key>
|
||||
<string>doAck:</string>
|
||||
<key>cdup</key>
|
||||
<string>doCdUp:</string>
|
||||
<key>cwd</key>
|
||||
<string>doCwd:</string>
|
||||
<key>dele</key>
|
||||
<string>doDele:</string>
|
||||
<key>eprt</key>
|
||||
<string>doEprt:</string>
|
||||
<key>epsv</key>
|
||||
<string>doEpsv:</string>
|
||||
<key>feat</key>
|
||||
<string>doFeat:</string>
|
||||
<key>list</key>
|
||||
<string>doList:</string>
|
||||
<key>lprt</key>
|
||||
<string>doLprt:</string>
|
||||
<key>mkd</key>
|
||||
<string>doMkdir:</string>
|
||||
<key>mlst</key>
|
||||
<string>doMlst:</string>
|
||||
<key>nlst</key>
|
||||
<string>doList:</string>
|
||||
<key>noop</key>
|
||||
<string>doNoop:</string>
|
||||
<key>opts</key>
|
||||
<string>doOpts:</string>
|
||||
<key>pass</key>
|
||||
<string>doPass:</string>
|
||||
<key>pasv</key>
|
||||
<string>doPasv:</string>
|
||||
<key>port</key>
|
||||
<string>doPort:</string>
|
||||
<key>pwd</key>
|
||||
<string>doPwd:</string>
|
||||
<key>quit</key>
|
||||
<string>doQuit:</string>
|
||||
<key>retr</key>
|
||||
<string>doRetr:</string>
|
||||
<key>rmd</key>
|
||||
<string>doDele:</string>
|
||||
<key>rnfr</key>
|
||||
<string>doRnfr:</string>
|
||||
<key>rnto</key>
|
||||
<string>doRnto:</string>
|
||||
<key>size</key>
|
||||
<string>doSize:</string>
|
||||
<key>stat</key>
|
||||
<string>doStat:</string>
|
||||
<key>stor</key>
|
||||
<string>doStor:</string>
|
||||
<key>syst</key>
|
||||
<string>doSyst:</string>
|
||||
<key>type</key>
|
||||
<string>doType:</string>
|
||||
<key>user</key>
|
||||
<string>doUser:</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -17,7 +17,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "FtpServer.h"
|
||||
#include <sys/stat.h>
|
||||
#include "dlfcn.h"
|
||||
|
||||
@@ -93,35 +92,6 @@ const char *IOS_GetExecDir(void)
|
||||
return dir;
|
||||
}
|
||||
|
||||
UIBackgroundTaskIdentifier task;
|
||||
FtpServer *server = NULL;
|
||||
|
||||
void IOS_StartBackgroundTask(void)
|
||||
{
|
||||
if( !server ) return;
|
||||
|
||||
if( task != UIBackgroundTaskInvalid )
|
||||
return;
|
||||
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
|
||||
task = [app beginBackgroundTaskWithExpirationHandler:^{
|
||||
[app endBackgroundTask:task];
|
||||
task = UIBackgroundTaskInvalid;
|
||||
}];
|
||||
|
||||
// Start the long-running task and return immediately.
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
UIBackgroundTaskIdentifier local = task;
|
||||
|
||||
// do not keep "zombie" tasks
|
||||
while( 1 )
|
||||
sleep(1);
|
||||
|
||||
[app endBackgroundTask:local];
|
||||
task = UIBackgroundTaskInvalid;
|
||||
});
|
||||
}
|
||||
|
||||
#define SETTINGS_MAGIC 111
|
||||
|
||||
@@ -203,8 +173,6 @@ void IOS_LaunchDialog( void )
|
||||
|
||||
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
|
||||
|
||||
UISwitch *ftpswitch = [[UISwitch alloc] initWithFrame:CGRectMake(210,60,80,30)];
|
||||
|
||||
UILabel *argstitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
|
||||
[argstitle setText:@"Command-line arguments:"];
|
||||
|
||||
@@ -213,12 +181,6 @@ void IOS_LaunchDialog( void )
|
||||
if(isdark) [args setBackgroundColor:[[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:1]];
|
||||
|
||||
|
||||
UILabel *ftptitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, 200, 30)];
|
||||
[ftptitle setText:@"FTP Server"];
|
||||
|
||||
|
||||
UITextField *port = [[UITextField alloc] initWithFrame:CGRectMake(110, 60, 100, 30)];
|
||||
|
||||
UITextField *suffix = [[UITextField alloc] initWithFrame:CGRectMake(140, 90, 160, 30 )];
|
||||
[suffix setBackgroundColor:[[UIColor alloc] initWithRed:1 green:1 blue:1 alpha:1]];
|
||||
if(isdark) [suffix setBackgroundColor:[[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:1]];
|
||||
@@ -229,9 +191,6 @@ void IOS_LaunchDialog( void )
|
||||
[scroll addSubview:argstitle];
|
||||
[scroll addSubview:args];
|
||||
[scroll addSubview:suffix];
|
||||
[scroll addSubview:ftpswitch];
|
||||
[scroll addSubview:ftptitle];
|
||||
[scroll addSubview:port];
|
||||
[scroll addSubview:suffixtitle];
|
||||
|
||||
settingsfile = fopen( settingspath, "rb" );
|
||||
@@ -240,14 +199,11 @@ void IOS_LaunchDialog( void )
|
||||
settings.args[1023] = 0;
|
||||
settings.suffix[31] = 0;
|
||||
[args setText:@(settings.args)];
|
||||
[port setText:[NSString stringWithFormat:@"%u", settings.port]];
|
||||
[suffix setText:@(settings.suffix)];
|
||||
ftpswitch.on = settings.ftpserver;
|
||||
}
|
||||
else
|
||||
{
|
||||
[args setText:@"-dev 2 -log"];
|
||||
[port setText:@"21135"];
|
||||
}
|
||||
|
||||
scroll.contentSize=CGSizeMake(250, 200);
|
||||
@@ -263,10 +219,8 @@ void IOS_LaunchDialog( void )
|
||||
|
||||
if( (settingsfile = fopen( settingspath, "wb" )) )
|
||||
{
|
||||
settings.ftpserver = ftpswitch.on;
|
||||
strlcpy(settings.args, [args.text UTF8String], 1024);
|
||||
strlcpy(settings.suffix, [suffix.text UTF8String], 32 );
|
||||
settings.port = [port.text intValue];
|
||||
settings.magic = 111;
|
||||
|
||||
fwrite(&settings, sizeof(settings), 1, settingsfile);
|
||||
@@ -278,25 +232,6 @@ void IOS_LaunchDialog( void )
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if( ftpswitch.on )
|
||||
{
|
||||
|
||||
button = -1;
|
||||
|
||||
[[[UIAlertView alloc] initWithTitle:@"Xash3D" message:[NSString stringWithFormat:@"Started FTP server on port %@", port.text] delegate:delegate cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
|
||||
|
||||
server = [[ FtpServer alloc ] initWithPort:[port.text integerValue] withDir:@(docsDir) notifyObject:nil ];
|
||||
|
||||
IOS_StartBackgroundTask();
|
||||
|
||||
@autoreleasepool {
|
||||
while( button == -1 ) {
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
||||
IOS_StartBackgroundTask(); // keep running
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSArray *argv = [ args.text componentsSeparatedByString:@" " ];
|
||||
|
||||
int count = [argv count];
|
||||
@@ -314,11 +249,8 @@ void IOS_LaunchDialog( void )
|
||||
|
||||
alert.delegate = nil;
|
||||
|
||||
[ftpswitch release];
|
||||
[ftptitle release];
|
||||
[args release];
|
||||
[argstitle release];
|
||||
[port release];
|
||||
[suffix release];
|
||||
[suffixtitle release];
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#pragma mark LS replacement
|
||||
NSString* createList(NSString* directoryPath);
|
||||
|
||||
#pragma mark Supporting Functions
|
||||
int filesinDirectory(NSString* filePath );
|
||||
NSMutableString* int2BinString(int x);
|
||||
NSMutableString *byte2String(int x );
|
||||
NSMutableString *bin2perms(NSString *binaryValue);
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
iosFtpServer
|
||||
Copyright (C) 2008 Richard Dearlove ( monsta )
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#import "list.h"
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
NSString* createList(NSString* directoryPath)
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSFileManager *fileManager = [ NSFileManager defaultManager ];
|
||||
NSDictionary *fileAttributes;
|
||||
NSError *error;
|
||||
|
||||
NSString* fileType;
|
||||
NSNumber* filePermissions;
|
||||
long fileSubdirCount;
|
||||
NSString* fileOwner;
|
||||
NSString* fileGroup;
|
||||
NSNumber* fileSize;
|
||||
NSDate* fileModified;
|
||||
NSString* fileDateFormatted;
|
||||
NSDateFormatter* dateFormatter = [[[ NSDateFormatter alloc ] init ] autorelease ];
|
||||
|
||||
BOOL fileIsDirectory;
|
||||
|
||||
|
||||
NSMutableString* returnString= [ NSMutableString new ];
|
||||
NSString* formattedString;
|
||||
|
||||
NSString* binaryString;
|
||||
|
||||
[returnString appendString:@"\r\n"];
|
||||
|
||||
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:directoryPath];
|
||||
NSString *filePath;
|
||||
|
||||
NSString* firstChar;
|
||||
NSString* fullFilePath;
|
||||
|
||||
[dateFormatter setDateFormat:@"MMM dd HH:mm"];
|
||||
NSLocale *englishLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
|
||||
[dateFormatter setLocale:englishLocale];
|
||||
[englishLocale release];
|
||||
|
||||
|
||||
NSLog(@"Get LS for %@", directoryPath );
|
||||
int numberOfFiles = 0;
|
||||
while (filePath = [dirEnum nextObject]) {
|
||||
|
||||
firstChar = [ filePath substringToIndex:1 ];
|
||||
|
||||
[dirEnum skipDescendents ]; // don't go down that recursive road
|
||||
|
||||
if ( ![ firstChar isEqualToString:@"."] ) // dont show hidden files
|
||||
{
|
||||
fullFilePath = [directoryPath stringByAppendingPathComponent:filePath];
|
||||
|
||||
fileAttributes = [ fileManager attributesOfItemAtPath:fullFilePath error:&error ];
|
||||
|
||||
fileType = [ fileAttributes valueForKey:NSFileType ];
|
||||
|
||||
filePermissions = [ fileAttributes valueForKey:NSFilePosixPermissions ];
|
||||
fileSubdirCount = filesinDirectory(fullFilePath);
|
||||
fileOwner = [ fileAttributes valueForKey:NSFileOwnerAccountName ];
|
||||
fileGroup = [ fileAttributes valueForKey:NSFileGroupOwnerAccountName ];
|
||||
fileSize = [ fileAttributes valueForKey:NSFileSize ];
|
||||
fileModified = [ fileAttributes valueForKey:NSFileModificationDate ];
|
||||
fileDateFormatted = [ dateFormatter stringFromDate:fileModified ];
|
||||
|
||||
fileIsDirectory = (fileType == NSFileTypeDirectory );
|
||||
|
||||
|
||||
fileSubdirCount = fileSubdirCount <1 ? 1 : fileSubdirCount;
|
||||
|
||||
binaryString = int2BinString([filePermissions unsignedLongValue]) ;
|
||||
binaryString = [ binaryString substringFromIndex:7 ];// snip off the front
|
||||
formattedString = [ NSString stringWithFormat:@"%@%@ %5i %12@ %12@ %10qu %@ %@", fileIsDirectory ? @"d" : @"-" ,bin2perms(binaryString),fileSubdirCount, fileOwner, fileGroup, [fileSize unsignedLongLongValue], fileDateFormatted , filePath ];
|
||||
|
||||
[ returnString appendString:formattedString ];
|
||||
[ returnString appendString:@"\n" ];
|
||||
numberOfFiles++;
|
||||
}
|
||||
}
|
||||
[returnString insertString: [NSString stringWithFormat:@"total %d", numberOfFiles] atIndex:0];
|
||||
// NSLog(returnString );
|
||||
return [returnString autorelease]; // FIXME - release count
|
||||
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
int filesinDirectory(NSString* filePath )
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
int no_files =0;
|
||||
NSFileManager *fileManager = [ NSFileManager defaultManager ];
|
||||
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:filePath];
|
||||
|
||||
while (filePath = [dirEnum nextObject]) {
|
||||
[dirEnum skipDescendents ]; // don't want children
|
||||
no_files++;
|
||||
}
|
||||
|
||||
return no_files;
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
NSMutableString* int2BinString(int x)
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSMutableString *returnString = [[ NSMutableString alloc ] init];
|
||||
int hi, lo;
|
||||
hi=(x>>8) & 0xff;
|
||||
lo=x&0xff;
|
||||
|
||||
[ returnString appendString:byte2String(hi) ];
|
||||
[ returnString appendString:byte2String(lo) ];
|
||||
return [ returnString autorelease ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
NSMutableString *byte2String(int x )
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSMutableString *returnString = [[ NSMutableString alloc ]init];
|
||||
|
||||
int n;
|
||||
|
||||
for(n=0; n<8; n++)
|
||||
{
|
||||
if((x & 0x80) !=0)
|
||||
{
|
||||
|
||||
[ returnString appendString:@"1"];
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
[ returnString appendString:@"0"];
|
||||
}
|
||||
x = x<<1;
|
||||
}
|
||||
|
||||
return [returnString autorelease];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
NSMutableString *bin2perms(NSString *binaryValue)
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
NSMutableString *returnString = [[ NSMutableString alloc ] init];
|
||||
NSRange subStringRange;
|
||||
subStringRange.length = 1;
|
||||
NSString *replaceWithChar;
|
||||
|
||||
for (int n=0; n < [binaryValue length]; n++)
|
||||
{
|
||||
subStringRange.location = n;
|
||||
// take the char
|
||||
// if pos = 0, 3,6
|
||||
if ( n == 0 || n == 3 || n ==6)
|
||||
{
|
||||
replaceWithChar = @"r";
|
||||
}
|
||||
if ( n == 1 || n == 4 || n ==7)
|
||||
{
|
||||
replaceWithChar = @"w";
|
||||
}
|
||||
if ( n == 2 || n == 5 || n ==7)
|
||||
{
|
||||
replaceWithChar = @"x";
|
||||
}
|
||||
|
||||
if ( [[binaryValue substringWithRange:subStringRange ] isEqualToString:@"1" ] )
|
||||
{
|
||||
[ returnString appendString:replaceWithChar ];
|
||||
}
|
||||
else
|
||||
{
|
||||
[ returnString appendString:@"-" ];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return [ returnString autorelease ];
|
||||
}
|
||||
|
||||
@@ -248,13 +248,6 @@ static void SDLash_ActiveEvent( int gain )
|
||||
}
|
||||
else
|
||||
{
|
||||
#if TARGET_OS_IPHONE
|
||||
{
|
||||
// Keep running if ftp server enabled
|
||||
void IOS_StartBackgroundTask( void );
|
||||
IOS_StartBackgroundTask();
|
||||
}
|
||||
#endif
|
||||
host.status = HOST_NOFOCUS;
|
||||
|
||||
if( cls.key_dest == key_game )
|
||||
|
||||
@@ -12,7 +12,6 @@ if [ -d "$BUILDDIR" ]; then
|
||||
|
||||
cp -r "$BUILDDIR/ios/libs/"* "$BUILDDIR/ios/xash3d.app"
|
||||
cp Info.plist "$BUILDDIR/ios/xash3d.app"
|
||||
cp ftp_commands.plist "$BUILDDIR/ios/xash3d.app"
|
||||
if [ ! -d "$BUILDDIR/SDL2.framework" ]; then
|
||||
echo "Couldn't find SDL2.framework, place it in the build directory"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user