StudiVZ plugin for Adium issues

studiVZ screenshot
Image by momentimedia via Flickr

So I just finished the first version of my StudiVZ plugin for AdiumX. It uses the XMPP<->SVZ gateway run by nimbuzz.com so an account for nimbuzz is needed as well to use the plugin. It can be found on the Adium Xtras page under plugins once it is cleared/reviewed.

While programming that I ran into a couple of interesting issues:

1) Adium plugins are packaged as bundles in OSX just like any other application, but cannot be diretly executed. They will be loaded by Adium on runtime and then executed in Adium’s context. If you need to link you bundle with dynamic libraries you would normally just include them inside the bundle and the linker finds it because the exucutable specifies a relative path which points inside the bundle as well. But since plugins are loaded inside the context of another running application, in this case Adium, which resides somewhere else in the FS, that executable-relative path does not help you. And an absolute one would’nt make you very happy either, since the install location of the plugin might vary. In linux there is a solution to this dilemma called RPATH. In MacOSX this also works. So instead of specifying the path to the dlib relative to the running executable – which is signified by ‘@executable_path’ in the output of ‘otool -L’ – it is specified relative to the currently loaded code which is called @loader_path. You can specify that inside XCode’s Active Target preferences for the plugin, the exact key is called ‘Runpath search path’. The Apple Dev. Conn. also tells us that the FW to be included needs to be built with the key of ‘installation directory’ set to @rpath and ‘dyn. lib isntall name’ to ‘@rpath/Name.framework/Versions/A’ because that is where FWs normally reside, but that does not seem to work as soon as you load more than one library or framework (at least for me). Both prefs together tell the dynloader to replace @rpath with the Runpath search path of the loading app (which should then be @loader_path) and add the path from the install name key.

But as I said, it did not work. So I started googling for the exact error message from the console and found some BB entries of people that had the same problem. Apparently, the solution is to use a tool called ‘install_name_tool’ which can change dynloader paths for dynlibs inside executables – very handy. Just call with the the string you want to have replaced and the one you want to replace it for, and you image name, and that’s it. In XCode this can be automated with a run-script build phase which should read something like this:

PATH=../Frameworks/RegexKit.framework/Versions/A/RegexKit
/usr/bin/install_name_tool -change "@executable_path/${PATH}"
"@loader_path/${PATH}"
"$TARGET_BUILD_DIR/$TARGET_NAME.$WRAPPER_EXTENSION/Contents/MacOS/$TARGET_NAME"

After I had found that out, I noticed the script in the Skype plugin XCode-project which also uses this, and copied it from there. This should work for any situation where you need to include a dynlib or FW inside another dynamically loaded piece of code (bundle) – in most cases plugins.

2) Since I could’nt figure out how to load the RegexKit inside my plug for a while, I defaulted to using POSIX extended RegExes directly. For that I used some code I found on http://homepage.mac.com/jrc/contrib/. Basically a thin wrapper around regex.h for NSStrings. Funny thing was that it seemed to work for the most part, when I tested it with short strings. But as soon as I used it with the whole HTML that I got back from studivz.net it also matched the right position, that is in byte positions inside the string, but when using NSString’s substringWithRange selector this was always a couple characters off. Apparantly this was due to a difference in encoding, ASCII in regex.h and UTF8 in NSString, and could have been solved easily. But this was ultimately so annoying coupled with the fact that it could’nt use full Perl-compatible REs anymore that I found the above described solution.

Advertisements

2 Responses to StudiVZ plugin for Adium issues

  1. Elbe says:

    Hi,
    thanks for your plugin.

    unfortunately it doesnt work for me, as soon as i click the “+” button to add a new service and then choose studivz adium crashes :/

  2. heru priadi says:

    thanks for ur article

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: