I'm having a problem here:
I have a C function:
int my_connect(int sockfd, const struct sockaddr *serv_addr,
socklen_t addrlen) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
alertViewDelegate = [FirewallRest alloc];
[alertViewDelegate retain];
//ALog(@"1");
int error;
//ALog(@"2");
char hostname[NI_MAXHOST] = "";
//ALog(@"3");
error = getnameinfo(serv_addr, addrlen, hostname, NI_MAXHOST, NULL, 0, 0);
//ALog(@"4");
if (error !=0) {
ALog(@"coudldn't resolve hostname or internal connect");
[pool release];
return orig__connect(sockfd, serv_addr, addrlen);
}
if (error == 0) {
ALog(@"hostname: %s", hostname);
NSString *hostFirst = [NSString stringWithCString:hostname];
NSString *host = [hostFirst stringByReplacingOccurrencesOfString:@"www." withString:@""];
NSString *msg = [@"tries to contact: " stringByAppendingString:host];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"asdf"
message:msg
delegate:alertViewDelegate cancelButtonTitle:@"Never allow!"
otherButtonTitles:@"1", @"2",@"3", nil];
[alert show];
[alert release];
waitingForResponse = YES;
while (waitingForResponse == YES) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ALog(@"running Loop1?");
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
ALog(@"running Loop2?");
[pool drain];
}
ALog(@"continues");
return orig__connect(sockfd, serv_addr, addrlen);
...
It should wait till the UIAlertViewDelegate method (in it's own class) sets waitingForResponse == NO.
extern BOOL waitingForResponse;
@implementation FirewallRest
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
//NSLog(@"buttonIndex: %@", buttonIndex);
if (buttonIndex == 0){
NSLog(@"0");
waitingForResponse = NO;
}
if (buttonIndex == 1){
NSLog(@"1");
waitingForResponse = NO;
}
if (buttonIndex == 2){
NSLog(@"2");
waitingForResponse = NO;
}
if (buttonIndex == 3){
NSLog(@"3");
waitingForResponse = NO;
}
}
but somehow that doesn't work :/
does anyone have an idea? or a better way to do this? (I'm not very used to C and objC in one app ;))
Thanks in advance for any help