eagleeye87

Posted
21 August 2007 @ 12pm

Tagged
Cocoa, Google Summer of Code

Comments Off

iChat File Transfer Analysis

Introduction

This summer I was fortunate enough to be selected as a student for Google Summer of Code 2007 to work on the Adium instant messenger. My specific project focuses on improving support for Bonjour messaging. I have worked on updating libezv which was originally written by my mentor, Andrew Wellington.

Within the past month work progressed towards the point where the last major feature was file transfer. I found a rather insightful post to Apple’s rendezvous-dev mailing list which helped immensely in deciphering iChat’s file transfer process.

As mentioned in the post, iChat adds custom attributes to the Jabber OOB Protocol. Unfortunately, these custom additions are the same portions lacking documentation. After more research, I have deduced what exactly these attributes are and how to use them!

File Transfer Process

The process for a typical transfer from iChat starts with an xml message similar to the following:

<message type="chat" to="erich@computer">
<body>Here is the file you asked for: </body>
<html xmlns="http://www.w3.org/1999/xhtml">
<body ichatballooncolor="#E68CBD" ichattextcolor="#000000">
<font ABSZ="12" face="Lucida Grande">Here is the file you asked for: </font>
</body>
</html>
<x xmlns="jabber:x:event">
<composing/>
</x>
<x xmlns="jabber:x:oob">
<url type="file" size="4" posixflags="000001A0" mimeType="text/plain"
hfsflags="00000008">http://192.168.1.100:40785/B554ECD98129158D/File.txt</url>
</x>
</message>

Most everything in the message is self explanatory except for the posixflags and hfsflags attributes. Both attributes hint at their meaning, however, I didn’t know what exactly was necessary to process the information. After some further documentation reading, the answer came rather easily.

Attribute Values

posixflags proved the easier attribute to decipher. In actuality this attribute merely gives the value for the NSFilePosixPermissions key in the file attribute dictionary converted to hexadecimal. Using this information then becomes as easy as converting the hexadecimal value to an NSNumber and then using NSFileManager to apply the value for the NSFilePosixPermissions key.

The meaning of hfsflags did not come as easily. Actually, the answer didn’t come until I was nearly finished finding another way to get information about the file. It turns out that hfsflags consists of the hexadecimal encoding of the finderFlags member of the FileInfo struct. The Finder Flags describes information about a file or folder such as whether the item has a finder label or whether it is an alias. Although the workaround mentioned before precluded any attempt at using this value, in theory application of the finderFlags would be as simple as recreating the FileInfo struct and then applying that information using a call to Carbon’s FSSetCatalogInfo().

Conclusion

Looking back the process to discover these attributes wasn’t very challenging, however, hopefully no one else will need to do research into what the posixflags and hfsflags attributes describe.


Posted
2 January 2007 @ 12pm

Tagged
Cocoa, Research

Comments Off

Cellular Automaton

Two years ago I worked on an interesting research project with a friend. In this project we examined a certain cellular automaton named Langton's Ants. Cellular automata are infinite grid spaces in which each space possesses a certain state. Spaces in Langton's Ants have one of two states, on or off. In this cellular automata, an "ant" traverses the infinite grid space. Each time the ant enters a square it follows a certain set of rules:

  1. If the square is 'on' the ant rotates 90 degrees clockwise and then moves forward one square.
  2. If the square is 'off' the ant rotates 90 degrees counterclockwise and then moves forward one square.
  3. When the ant leaves a square it switches the status.

Although these rules seem simple, the patterns produced are intriguing. Because of this, I decided to adapt some of the code written for the research project into a screen saver for Mac OS X. The screen saver randomly creates anywhere from 1 to 5 ants on a grid and then performs the simple rules for each ant. The following image is a pattern created by a single "ant."

cellularautomaton_1.png

Screen Saver
I am releasing the CellularAutomaton v1.0 screen saver today. I have only tested this on Mac OS X 10.4.8 on Intel and PowerPC computers. Because of this I do not know whether this will work on any version of Mac OS X below 10.4.8 (including 10.3.x and below). I hope you enjoy watching the amazing display as much as I enjoyed researching the automaton.

Click here to Download

Installation
To use the screen saver simply double-click the CellularAutomaton.saver file. Follow the directions and then navigate to the CellularAutomaton screen saver in the list of screen savers.

Images If you ever wish to save a pattern that appears on your screen simply press the s key. Once you hear a beep, a file starting with CellularAutomaton has been saved to your Desktop.

Note: Because of this feature the s key will not stop the screen saver.

I am interested to see all of the interesting images so feel free to email them to me. I hope to create a gallery of user-submitted images.

Options

cellularautomatonoptions.png

As shown above, there are few preferences which allow you to change the display behavior of the screen saver.

Questions?
If you do have any questions or run into any problems either leave a comment on this post or email me.

Further Reading
If you are interested in cellular automata or specifically Langton's Ants I suggest you explore the following links:

Langton's Ants at Mathworld
Cellular automata at Mathworld