mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-10 06:02:10 +08:00
Restore iOS build support (#2352)
* initial commit * initial commit * add port files * ios: Changes to allow creating app bundle without xcode projects * ios: Added mic perms request * ios: Very basic app bundle creation script * ios: Fix -log parameter * ios: Sdk no longer hardcoded and option to compile for simulator * general: Update gitignore * ios: Enable game mode for the app * ios: Compile instructions and updated ipa creation script * ios: Code cleanup * ios: Remove dylibs * general: Remove extra submodules * ios: Remove dylibs again * ios: Implement suggested changes * ios: Fix building as dylib instead of binary * ios: Scripts for building mods * ios: Move 'ios' contents to engine/platform/ios/bundle and modify scripts * ios: Update createipa.sh to use waf install * ios: Clean script and updated README * general: Fix spelling mistake and outdated instructions * ios: Clean up in xcompile.py * ios: Fix createipa.sh generating an invalid ipa * ios: Temporary fix for launch dialog textfield colors in dark mode
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
//
|
||||
// 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
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
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
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
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
|
||||
@@ -0,0 +1,15 @@
|
||||
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
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
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
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// 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
|
||||
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// 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
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
SDL_uikit_main.c, placed in the public domain by Sam Lantinga 3/18/2019
|
||||
*/
|
||||
|
||||
/* Include the SDL main definition header */
|
||||
#include "SDL_main.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__TVOS__)
|
||||
|
||||
#ifndef SDL_MAIN_HANDLED
|
||||
#ifdef main
|
||||
#undef main
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return SDL_UIKitRunApp(argc, argv, SDL_main);
|
||||
}
|
||||
#endif /* !SDL_MAIN_HANDLED */
|
||||
|
||||
#endif /* __IPHONEOS__ || __TVOS__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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>BuildMachineOSBuild</key>
|
||||
<string>25A362</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>xash</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>su.xash.engine</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>xash3d-fwgs</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>iPhoneOS</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>23A339</string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>iphoneos</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>26.0</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23A339</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>iphoneos26.0</string>
|
||||
<key>DTXcode</key>
|
||||
<string>2601</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>17A400</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>LSSupportsGameMode</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>12.0</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>Microphone permissions are required for voice chat</string>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>UIFileSharingEnabled</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>Launch</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>arm64</string>
|
||||
</array>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UIStatusBarStyle</key>
|
||||
<string>UIStatusBarStyleLightContent</string>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportsDocumentBrowser</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,334 @@
|
||||
/*
|
||||
launchdialog.m - iOS lauch dialog
|
||||
Copyright (C) 2016 mittorn
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "SDL_syswm.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "FtpServer.h"
|
||||
#include <sys/stat.h>
|
||||
#include "dlfcn.h"
|
||||
|
||||
#ifndef XASH_GAMEDIR
|
||||
#define XASH_GAMEDIR "valve" // !!! Replace with your default (base) game directory !!!
|
||||
#endif
|
||||
#define XASHLIB "@rpath/libxash.dylib"
|
||||
|
||||
|
||||
@interface XashPromptAlertViewDelegate : NSObject <UIAlertViewDelegate>
|
||||
|
||||
@property (nonatomic, assign) int *button;
|
||||
|
||||
@end
|
||||
|
||||
@implementation XashPromptAlertViewDelegate
|
||||
|
||||
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
||||
*_button = buttonIndex;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
int szArgc;
|
||||
char **szArgv;
|
||||
char *g_szLibrarySuffix;
|
||||
float g_iOSVer;
|
||||
bool isdark;
|
||||
|
||||
const char *IOS_GetDocsDir(void)
|
||||
{
|
||||
if( g_iOSVer >= 8.0 )
|
||||
{
|
||||
static const char *dir = NULL;
|
||||
|
||||
if( dir )
|
||||
return dir;
|
||||
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDirctory = [paths objectAtIndex:0];
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirctory withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
|
||||
dir = [documentsDirctory fileSystemRepresentation];
|
||||
NSLog(@"IOS_GetDocsDir: %s", dir);
|
||||
|
||||
return dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
static char dir[1024];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *basePath = paths.firstObject;
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
strcpy(dir,[basePath UTF8String]);
|
||||
mkdir(dir,777);
|
||||
|
||||
NSLog(@"IOS_GetDocsDir: %s", dir);
|
||||
|
||||
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
|
||||
|
||||
typedef struct settings_s
|
||||
{
|
||||
unsigned char magic;
|
||||
char args[1024];
|
||||
unsigned int port;
|
||||
char suffix[32];
|
||||
unsigned int ftpserver;
|
||||
} settings_t;
|
||||
@interface ButtonHandler :NSObject
|
||||
@property (nonatomic, assign) int *button1;
|
||||
@end
|
||||
@implementation ButtonHandler
|
||||
|
||||
|
||||
-(void) buttonClicked:(UIButton*)sender
|
||||
{
|
||||
*_button1 = 0;
|
||||
}
|
||||
@end
|
||||
void IOS_PrepareView(void)
|
||||
{
|
||||
ButtonHandler *handler = [[ButtonHandler alloc] init];
|
||||
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
UIViewController *controller = [[UIViewController alloc] init];
|
||||
[[controller view] setBackgroundColor:[UIColor grayColor]];
|
||||
[window setRootViewController:controller];
|
||||
[window makeKeyAndVisible];
|
||||
if([[controller traitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark && g_iOSVer >= 13.0) isdark = true; else isdark = false;
|
||||
#if 0
|
||||
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
|
||||
int button1 = -1;
|
||||
handler.button1 = &button1;
|
||||
|
||||
[button addTarget:handler action:@selector(buttonClicked:) forControlEvents:UIControlEventValueChanged];
|
||||
@autoreleasepool {
|
||||
while( button1 == -1 ) {
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
||||
}
|
||||
}
|
||||
[[controller view] addSubview:button];
|
||||
#endif
|
||||
}
|
||||
|
||||
void IOS_LaunchDialog( void )
|
||||
{
|
||||
NSLog(@"System Version is %@",[[UIDevice currentDevice] systemVersion]);
|
||||
NSString *ver = [[UIDevice currentDevice] systemVersion];
|
||||
g_iOSVer = [ver floatValue];
|
||||
|
||||
//request microphone permissions otherwise we will crash when joining an online server
|
||||
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted){}];
|
||||
|
||||
IOS_PrepareView();
|
||||
int button = -1, bExit, bStart;
|
||||
UIAlertView * alert = [[UIAlertView alloc] init];
|
||||
bExit = [alert addButtonWithTitle:@"Exit"];
|
||||
bStart = [alert addButtonWithTitle:@"Start"];
|
||||
XashPromptAlertViewDelegate *delegate = [[XashPromptAlertViewDelegate alloc] init];
|
||||
delegate.button = &button;
|
||||
|
||||
alert.delegate = delegate;
|
||||
|
||||
const char *docsDir = IOS_GetDocsDir();
|
||||
|
||||
//set working directory to documents so logs can be generated there
|
||||
NSString *workingDir = [NSString stringWithUTF8String:IOS_GetDocsDir()];
|
||||
[[NSFileManager defaultManager] changeCurrentDirectoryPath:workingDir];
|
||||
|
||||
FILE *settingsfile;
|
||||
char settingspath[256];
|
||||
snprintf(settingspath, sizeof(settingspath), "%s/settings.bin", docsDir );
|
||||
settingspath[255] = 0;
|
||||
settings_t settings;
|
||||
|
||||
[alert setTransform:CGAffineTransformMakeTranslation(0,109)];
|
||||
|
||||
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:"];
|
||||
|
||||
UITextField *args = [[UITextField alloc] initWithFrame:CGRectMake(0, 30, 300, 30)];
|
||||
[args setBackgroundColor:[[UIColor alloc] initWithRed:1 green:1 blue:1 alpha:1]];
|
||||
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]];
|
||||
|
||||
UILabel *suffixtitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, 140, 30)];
|
||||
[suffixtitle setText:@"Library suffix"];
|
||||
|
||||
[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" );
|
||||
if( settingsfile && ( fread(&settings, sizeof( settings ), 1, settingsfile ) == 1 ) && ( settings.magic == SETTINGS_MAGIC ) )
|
||||
{
|
||||
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);
|
||||
[alert setValue:scroll forKey:@"accessoryView"];
|
||||
|
||||
[alert show];
|
||||
|
||||
@autoreleasepool {
|
||||
while( button == -1 ) {
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
fclose(settingsfile);
|
||||
}
|
||||
if( button == bExit )
|
||||
{
|
||||
printf("Exit selected\n");
|
||||
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];
|
||||
szArgv = calloc( count + 2, sizeof( char* ) );
|
||||
int i;
|
||||
for( i = 0; i<count; i++ )
|
||||
{
|
||||
szArgv[i + 1] = strdup( [argv[i] UTF8String] );
|
||||
}
|
||||
szArgc = count + 1;
|
||||
szArgv[count + 1] = 0;
|
||||
|
||||
if( [suffix.text length] )
|
||||
g_szLibrarySuffix = strdup([suffix.text UTF8String]);
|
||||
|
||||
alert.delegate = nil;
|
||||
|
||||
[ftpswitch release];
|
||||
[ftptitle release];
|
||||
[args release];
|
||||
[argstitle release];
|
||||
[port release];
|
||||
[suffix release];
|
||||
[suffixtitle release];
|
||||
|
||||
[alert release];
|
||||
}
|
||||
|
||||
char *IOS_GetUDID( void )
|
||||
{
|
||||
static char udid[256];
|
||||
NSString *id = [[[UIDevice currentDevice]identifierForVendor] UUIDString];
|
||||
strncpy( udid, [id UTF8String], 255 );
|
||||
[id release];
|
||||
return udid;
|
||||
}
|
||||
|
||||
void IOS_Log(const char *text)
|
||||
{
|
||||
NSLog(@"Xash: %@", [NSString stringWithUTF8String:text]);
|
||||
}
|
||||
|
||||
int IOS_GetArgs( char ***out )
|
||||
{
|
||||
*out = szArgv;
|
||||
return szArgc;
|
||||
}
|
||||
@@ -12,13 +12,14 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
#if TARGET_OS_IPHONE
|
||||
#include <string.h>
|
||||
#include <SDL.h>
|
||||
#include "common.h"
|
||||
#include "library.h"
|
||||
#include "filesystem.h"
|
||||
#include "server.h"
|
||||
#include "platform/apple/ios_lib.h"
|
||||
#include "platform/ios/lib_ios.h"
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void *IOS_LoadLibraryInternal( const char *dllname )
|
||||
{
|
||||
@@ -52,20 +53,19 @@ static void *IOS_LoadLibraryInternal( const char *dllname )
|
||||
}
|
||||
return pHandle;
|
||||
}
|
||||
extern char *g_szLibrarySuffix;
|
||||
static void *IOS_LoadLibrary( const char *dllname )
|
||||
char *g_szLibrarySuffix;
|
||||
void *IOS_LoadLibrary( const char *dllname )
|
||||
{
|
||||
|
||||
string name;
|
||||
char *postfix = g_szLibrarySuffix;
|
||||
char *pHandle;
|
||||
|
||||
if( !postfix ) postfix = GI->gamefolder;
|
||||
|
||||
Q_snprintf( name, MAX_STRING, "%s_%s", dllname, postfix );
|
||||
|
||||
if( !postfix ) postfix = "";
|
||||
|
||||
Q_snprintf( name, MAX_STRING, "%s%s", dllname, postfix );
|
||||
pHandle = IOS_LoadLibraryInternal( name );
|
||||
if( pHandle )
|
||||
return pHandle;
|
||||
return IOS_LoadLibraryInternal( dllname );
|
||||
}
|
||||
#endif // TARGET_OS_IPHONE
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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);
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
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 ];
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ qboolean Platform_DebuggerPresent( void );
|
||||
|
||||
// legacy iOS port functions
|
||||
#if TARGET_OS_IOS
|
||||
int IOS_GetArgs( char ***argv );
|
||||
const char *IOS_GetDocsDir( void );
|
||||
void IOS_LaunchDialog( void );
|
||||
#endif // TARGET_OS_IOS
|
||||
|
||||
@@ -36,7 +36,7 @@ GNU General Public License for more details.
|
||||
#include "filesystem.h"
|
||||
#include "server.h"
|
||||
#include "platform/android/lib_android.h"
|
||||
#include "platform/apple/lib_ios.h"
|
||||
#include "platform/ios/lib_ios.h"
|
||||
|
||||
#ifdef XASH_NO_LIBDL
|
||||
void *dlsym( void *handle, const char *symbol )
|
||||
|
||||
@@ -496,10 +496,9 @@ static qboolean VID_SetScreenResolution( int width, int height, window_mode_t wi
|
||||
{
|
||||
SDL_DisplayMode got;
|
||||
Uint32 wndFlags = 0;
|
||||
|
||||
|
||||
if( vid_highdpi.value )
|
||||
SetBits( wndFlags, SDL_WINDOW_ALLOW_HIGHDPI );
|
||||
|
||||
SDL_SetWindowBordered( host.hWnd, SDL_FALSE );
|
||||
|
||||
if( window_mode == WINDOW_MODE_BORDERLESS )
|
||||
|
||||
Reference in New Issue
Block a user