Problem with cocoa async sockets

2010-09-05 Thread Samuli Lehtonen
Hey I started using cocoa sockets sometime ago, so here is the code I got now, 
I am using the echo server example as server which was provided with the class. 
So what I am trying to do is, send a message from the server to client when the 
server receives the message, server gets the message, but client won't get the 
message that server is sending somehow. Only message client gets is the welcome 
message , I don't understand why it won't get the other messages, I've really 
struggled with this now, thanks in advance, I am more than grateful for help!

For the async socket class http://code.google.com/p/cocoaasyncsocket/

I was recommended to use this class for networking on forums, so I used it and 
it seems to be pretty simple expect my problem is pretty weird..

Here is server .m file

#import "AppController.h"
#import "AsyncSocket.h"

#define WELCOME_MSG  0
#define ECHO_MSG 1

#define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__]

@interface AppController (PrivateAPI)
- (void)logError:(NSString *)msg;
- (void)logInfo:(NSString *)msg;
- (void)logMessage:(NSString *)msg;
@end


@implementation AppController

- (id)init
{
if(self = [super init])
{
listenSocket = [[AsyncSocket alloc] initWithDelegate:self];
connectedSockets = [[NSMutableArray alloc] initWithCapacity:1];

isRunning = NO;
}
return self;
}

- (void)awakeFromNib
{
[logView setString:@""];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"Ready");

// Advanced options - enable the socket to contine operations even 
during modal dialogs, and menu browsing
[listenSocket setRunLoopModes:[NSArray 
arrayWithObject:NSRunLoopCommonModes]];
}

- (void)scrollToBottom
{
NSScrollView *scrollView = [logView enclosingScrollView];
NSPoint newScrollOrigin;

if ([[scrollView documentView] isFlipped])
newScrollOrigin = NSMakePoint(0.0, NSMaxY([[scrollView 
documentView] frame]));
else
newScrollOrigin = NSMakePoint(0.0, 0.0);

[[scrollView documentView] scrollPoint:newScrollOrigin];
}

- (void)logError:(NSString *)msg
{
NSString *paragraph = [NSString stringWithFormat:@"%...@\n", msg];

NSMutableDictionary *attributes = [NSMutableDictionary 
dictionaryWithCapacity:1];
[attributes setObject:[NSColor redColor] 
forKey:NSForegroundColorAttributeName];

NSAttributedString *as = [[NSAttributedString alloc] 
initWithString:paragraph attributes:attributes];
[as autorelease];

[[logView textStorage] appendAttributedString:as];
[self scrollToBottom];
}

- (void)logInfo:(NSString *)msg
{
NSString *paragraph = [NSString stringWithFormat:@"%...@\n", msg];

NSMutableDictionary *attributes = [NSMutableDictionary 
dictionaryWithCapacity:1];
[attributes setObject:[NSColor purpleColor] 
forKey:NSForegroundColorAttributeName];

NSAttributedString *as = [[NSAttributedString alloc] 
initWithString:paragraph attributes:attributes];
[as autorelease];

[[logView textStorage] appendAttributedString:as];
[self scrollToBottom];
}

- (void)logMessage:(NSString *)msg
{
NSString *paragraph = [NSString stringWithFormat:@"%...@\n", msg];

NSMutableDictionary *attributes = [NSMutableDictionary 
dictionaryWithCapacity:1];
[attributes setObject:[NSColor blackColor] 
forKey:NSForegroundColorAttributeName];

NSAttributedString *as = [[NSAttributedString alloc] 
initWithString:paragraph attributes:attributes];
[as autorelease];

[[logView textStorage] appendAttributedString:as];
[self scrollToBottom];
}

- (IBAction)startStop:(id)sender
{
if(!isRunning)
{
int port = [portField intValue];

if(port < 0 || port > 65535)
{
port = 0;
}

NSError *error = nil;
if(![listenSocket acceptOnPort:port error:&error])
{
[self logError:FORMAT(@"Error starting server: %@", 
error)];
return;
}

[self logInfo:FORMAT(@"Echo server started on port %hu", 
[listenSocket localPort])];
isRunning = YES;

[portField setEnabled:NO];
[startStopButton setTitle:@"Stop"];
}
else
{
// Stop accepting connections
[listenSocket disconnect];

// Stop any client connections
int i;
for(i = 0; i < [connectedSockets count]; i++)
{
  

Privileged file deletion using BetterAuthSample (factored application) : secure?

2010-09-05 Thread Michaël Fortin
Hi everyone, first mail here.

I am making a small app which needs to delete some files that require 
privileged access (log files that the user doesn't have permissions to modify).

Currently I am deleting files using NSTask with rm or srm.

I looked at the Security Services documentation and it seems to me that the 
"factored application" method is the most secure way to proceed with 
authentication to allow deletion of protected files. After further digging I 
found the BetterAuthSample code that (from what I've seen) is the recommended 
way to implement the factored application approach.

My question is as follows: Is the BAS approach secure in this particular 
context?

Let me explain my understanding of how BAS works and why I think it might be 
insecure in this case. Please correct me if I'm wrong.

My understanding is that the Helper Tool implements a protocol allowing it to 
respond to application commands. In my case I would have a command which takes 
a file path and secure deletion mode as input. This helper tool is installed in 
a privileged directory which grants the tool the right to perform privileged 
operations. *after the initial installation authentication, the tool is 
installed in the privileged folder and it always possesses the right to delete 
privileged files without further authentication*. So what that would mean is 
that any application could potentially pass a file and secure deletion mode and 
have it deleted.

I'm sure there's something wrong in that reasoning because it doesn't seem 
logical that any app could use the tool once it's installed, but by reading the 
documentation I'm not sure exactly if and how the helper tool makes sure it's 
only used by my application.

Thanks in advance for any clarification.

Regards,
Michaël Fortin
www.irradiated.net
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Disable exceptions in Objective-C++ files when building for x86_64?

2010-09-05 Thread James Dolan
Forgive me if this is the wrong list for this question, but I have the
strangest problem.

I just noticed that '-fno-exceptions' has no effect on .m or .mm
files, but only when '-arch x86_64' is set. In other words,
__EXCEPTIONS is raised when it shouldn't be.

It should be easy for anyone to repro... just run the following
commands in Terminal.

exceptions still enabled!
  gcc -fno-exceptions -arch x86_64 -dM -E -x objective-c++ - <<<'' |
grep __EXCEPTIONS

exceptions not enabled.
  gcc -fno-exceptions -arch i386 -dM -E -x objective-c++ - <<<'' |
grep __EXCEPTIONS
  gcc -fno-exceptions -arch x86_64 -dM -E -x c++ - <<<'' | grep __EXCEPTIONS

-james
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fixed pattern with colorWithPatternImage

2010-09-05 Thread Daniel Lopes
Thanks everybody. I'm without my mac now, so I will try all the recomendations 
tomorrow, anyway... big thanks for all help (until now I didnt found a good a 
place where I can have help to learn Cocoa for Mac, and not iPhone).

Sent from my iPad

On 05/09/2010, at 19:42, Ken Ferry  wrote:

> 
> 
> On Sun, Sep 5, 2010 at 3:41 PM, Ken Ferry  wrote:
> 
> 
> On Sat, Sep 4, 2010 at 1:16 PM, Daniel Lopes  wrote:
> Hello Quincey,
> 
> Thanks, I thought that a simple thing like that could be done easier. My 
> background is from web dev (specially Ruby).
> 
> NSDrawThreePartImage looks like it should be very easy in this case.  In 
> fact, it looks like you do have a separate top image (though you could pass 
> nil if you didn't).
> 
> Oh, you probably want to go left to right, not top to bottom.
> 
> Nevertheless, it's one function call.
> 
> -Ken
> 
>  
> 
> -Ken
>  
> 
> That app is just a simple pet project and for that I will use a simple 
> gradient instead of the image. I tried the image because I want a small noise 
> instead of a plain gradient.
> 
> But really thanks for all the help, I will study the link that you sent and 
> also study Coregraphics.
> 
> Sent from my iPad
> 
> On 04/09/2010, at 14:52, Quincey Morris  wrote:
> 
> > On Sep 4, 2010, at 10:13, Daniel - Area wrote:
> >
> >> My code is basically this:
> >> http://pastie.org/1138167
> >>
> >> a) Looking my code I think the issue is exactly what you said. But
> >> what is the right object and properties to access the full size of the
> >> view?
> >
> > No, what I said is not the problem. You're not using the 'rect' parameter 
> > at all.
> >
> > Consulting the 'colorWithPatternImage:' documentation:
> >
> >> Parameters
> >> image
> >> The image to use as the pattern for the color object. The image is tiled 
> >> starting at the bottom of the window. The image is not scaled.
> >
> > The pattern is tiled relative to the window, not to the view. So, the 
> > 'colorWithPatternImage:' isn't a viable approach in this case.
> >
> > You're going to have to browse the documentation to find a different 
> > approach (or search for sample code you can adapt). One possibility might 
> > be NSGradient, another might be NSDrawThreePartImage. These are both 
> > discussed here:
> >
> >   
> > http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html
> >
> > Or, you might be able to drop down to core graphics, and use something like 
> > CGContextDrawTiledImage.
> >
> >
> >
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post admin requests or moderator comments to the list.
> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> >
> > Help/Unsubscribe/Update your Subscription:
> > http://lists.apple.com/mailman/options/cocoa-dev/danielvlopes%40gmail.com
> >
> > This email sent to danielvlo...@gmail.com
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com
> 
> This email sent to kenfe...@gmail.com
> 
> 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Highlight Text like with FIne

2010-09-05 Thread Brad Stone
I want to highlight different substrings contained in controls in a window (two 
different comboBoxes for example) programmatically when the user is searching 
for a subString.  I can do this for one comboBox but not both simultaneously.  
Here's one.

NSString *s = [titleComboBox stringValue];
NSRange r = [s rangeOfString:searchText options:NSCaseInsensitiveSearch 
range:NSMakeRange(0, [s length])];
[titleComboBox selectText:w];   
if (r.location != NSNotFound) {
// this is needed to select the substring
NSText *textEditor = [w fieldEditor:YES forObject:titleComboBox];
[textEditor setSelectedRange:r];
}

But this only highlights the text in the titleComboBox.  If I then repeat this 
to highlight the  text in the categoryComboBox by repeating the code, 
titleComboBox gets deselected and categoryComboBox gets selected.  I want to 
highlight them both simultaneously.  I'd also rather use the big yellow 
highlight like with the find panel (but that's later).

Is this possible? 

Thanks___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fixed pattern with colorWithPatternImage

2010-09-05 Thread Ken Ferry
On Sun, Sep 5, 2010 at 3:41 PM, Ken Ferry  wrote:

>
>
> On Sat, Sep 4, 2010 at 1:16 PM, Daniel Lopes wrote:
>
>> Hello Quincey,
>>
>> Thanks, I thought that a simple thing like that could be done easier. My
>> background is from web dev (specially Ruby).
>>
>
> NSDrawThreePartImage looks like it should be very easy in this case.  In
> fact, it looks like you do have a separate top image (though you could pass
> nil if you didn't).
>

Oh, you probably want to go left to right, not top to bottom.

Nevertheless, it's one function call.

-Ken



>
> -Ken
>
>
>>
>> That app is just a simple pet project and for that I will use a simple
>> gradient instead of the image. I tried the image because I want a small
>> noise instead of a plain gradient.
>>
>> But really thanks for all the help, I will study the link that you sent
>> and also study Coregraphics.
>>
>> Sent from my iPad
>>
>> On 04/09/2010, at 14:52, Quincey Morris 
>> wrote:
>>
>> > On Sep 4, 2010, at 10:13, Daniel - Area wrote:
>> >
>> >> My code is basically this:
>> >> http://pastie.org/1138167
>> >>
>> >> a) Looking my code I think the issue is exactly what you said. But
>> >> what is the right object and properties to access the full size of the
>> >> view?
>> >
>> > No, what I said is not the problem. You're not using the 'rect'
>> parameter at all.
>> >
>> > Consulting the 'colorWithPatternImage:' documentation:
>> >
>> >> Parameters
>> >> image
>> >> The image to use as the pattern for the color object. The image is
>> tiled starting at the bottom of the window. The image is not scaled.
>> >
>> > The pattern is tiled relative to the window, not to the view. So, the
>> 'colorWithPatternImage:' isn't a viable approach in this case.
>> >
>> > You're going to have to browse the documentation to find a different
>> approach (or search for sample code you can adapt). One possibility might be
>> NSGradient, another might be NSDrawThreePartImage. These are both discussed
>> here:
>> >
>> >
>> http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html
>> >
>> > Or, you might be able to drop down to core graphics, and use something
>> like CGContextDrawTiledImage.
>> >
>> >
>> >
>> > ___
>> >
>> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> >
>> > Please do not post admin requests or moderator comments to the list.
>> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> >
>> > Help/Unsubscribe/Update your Subscription:
>> >
>> http://lists.apple.com/mailman/options/cocoa-dev/danielvlopes%40gmail.com
>> >
>> > This email sent to danielvlo...@gmail.com
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com
>>
>> This email sent to kenfe...@gmail.com
>>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fixed pattern with colorWithPatternImage

2010-09-05 Thread Ken Ferry
On Sat, Sep 4, 2010 at 1:16 PM, Daniel Lopes  wrote:

> Hello Quincey,
>
> Thanks, I thought that a simple thing like that could be done easier. My
> background is from web dev (specially Ruby).
>

NSDrawThreePartImage looks like it should be very easy in this case.  In
fact, it looks like you do have a separate top image (though you could pass
nil if you didn't).

-Ken


>
> That app is just a simple pet project and for that I will use a simple
> gradient instead of the image. I tried the image because I want a small
> noise instead of a plain gradient.
>
> But really thanks for all the help, I will study the link that you sent and
> also study Coregraphics.
>
> Sent from my iPad
>
> On 04/09/2010, at 14:52, Quincey Morris 
> wrote:
>
> > On Sep 4, 2010, at 10:13, Daniel - Area wrote:
> >
> >> My code is basically this:
> >> http://pastie.org/1138167
> >>
> >> a) Looking my code I think the issue is exactly what you said. But
> >> what is the right object and properties to access the full size of the
> >> view?
> >
> > No, what I said is not the problem. You're not using the 'rect' parameter
> at all.
> >
> > Consulting the 'colorWithPatternImage:' documentation:
> >
> >> Parameters
> >> image
> >> The image to use as the pattern for the color object. The image is tiled
> starting at the bottom of the window. The image is not scaled.
> >
> > The pattern is tiled relative to the window, not to the view. So, the
> 'colorWithPatternImage:' isn't a viable approach in this case.
> >
> > You're going to have to browse the documentation to find a different
> approach (or search for sample code you can adapt). One possibility might be
> NSGradient, another might be NSDrawThreePartImage. These are both discussed
> here:
> >
> >
> http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html
> >
> > Or, you might be able to drop down to core graphics, and use something
> like CGContextDrawTiledImage.
> >
> >
> >
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post admin requests or moderator comments to the list.
> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> >
> > Help/Unsubscribe/Update your Subscription:
> >
> http://lists.apple.com/mailman/options/cocoa-dev/danielvlopes%40gmail.com
> >
> > This email sent to danielvlo...@gmail.com
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com
>
> This email sent to kenfe...@gmail.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fixed pattern with colorWithPatternImage

2010-09-05 Thread James Montgomerie
On 04/09/2010, at 14:52, Quincey Morris  wrote:
> The pattern is tiled relative to the window, not to the view. So, the 
> 'colorWithPatternImage:' isn't a viable approach in this case. 

Quincey may be right that drawing the image directly is the easier approach, 
but it /is/ possible to change the offset of a pattern image by altering the 
graphics context's pattern phase.  Before you draw:

CGFloat offset = ;

CGContextSetPatternPhase((CGContextRef)[[NSGraphicsContext currentContext] 
graphicsPort], CGSizeMake(0, offset));

[Typed in Mail, so not checked for syntax errors].

Jamie.___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: QTMovie Error -2048

2010-09-05 Thread Klaus Backert


On 5 Sep 2010, at 15:01, Mr. Gecko wrote:

I do not know if this is the right place to ask, I would think the  
quicktime list would be best, but, I am using cocoa to interface  
with quicktime so here it goes.
I have a customer who is getting error -2048 on my application, from  
my research it looks like it's an error with quicktime not being  
able to detect the file format, I believe the reason it can't detect  
this is because I'm loading from a URL without an extension (E.G. http://example.com/audio/2389f892988v998.) 
 How might I fix this, can I fix this, or do I have to give  
instructions to my customer on how to fix this? I haven't had anyone  
else with this problem, I am considering moving to NSSound and  
making my own controls, but I don't know if I'll have the same error  
there. I cannot change the URL for the mp3 files as it'll miss up my  
system.


In case you haven't found this already:




i.e. your customer's file is not a movie file.

regards
Klaus

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


QTMovie Error -2048

2010-09-05 Thread Mr. Gecko
I do not know if this is the right place to ask, I would think the quicktime 
list would be best, but, I am using cocoa to interface with quicktime so here 
it goes.
I have a customer who is getting error -2048 on my application, from my 
research it looks like it's an error with quicktime not being able to detect 
the file format, I believe the reason it can't detect this is because I'm 
loading from a URL without an extension (E.G. 
http://example.com/audio/2389f892988v998.) How might I fix this, can I fix 
this, or do I have to give instructions to my customer on how to fix this? I 
haven't had anyone else with this problem, I am considering moving to NSSound 
and making my own controls, but I don't know if I'll have the same error there. 
I cannot change the URL for the mp3 files as it'll miss up my system.

Thanks,
Mr. Gecko

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com