Asterisk Extended

Playing around with Asterisk, it was inevitable for me to stumble upon AGI.

AGI is a protocol quite like CGI which allows third party applications to be plugged into asterisk, giving them full control over the call handling. That way, even non-asterisk-developers are able to write interesting telephony applications.

One thing I always wanted to do is to set the CallerID on incoming calls. Some numbers are stored in our customer database. There is no reason not to show the customer names on the phones displays instead of only the number.

The snom phones do have a little addressbook, but it’s very limited in both amount of memory and featureset, so it was clear that I’ll have to set the CallerID via Asterisk (SIP allows for transmission of a caller-id. And so does AGI)

Additionally, I thought, it would be very nice to use the swiss phone book at tel.search.ch or even the non-free ETV to try and guess numbers not already in our database.

That scenario is exactly what AGI is for.

As AGI works like CGI, it creates a new process for every call to AGI applications. This is not an option if you want to use interpreted languages. Well. it *is* an option considering our low amount of calls we are getting per time unit, but still. I don’t like to deploy solutions with obvious drawbacks.

Besides, launching a PHP interpreter (I’d have written this in PHP) can easily take a second or so – not acceptable if you want the AGI script to be mandatory on each call. Think of it. You don’t want the caller to wait for your application.

The solution to this is FastAGI, which works like FastCGI: A server keeps running and answers AGI-requests. Like this, you start the interpreter once and just serve the calls in the future. You save the startup-time of the interpreter.

Even better: It allows to run the AGI applications on a different machine than the PBX. This is good because you want the PBX to have as much CPU time slices as possible.

Unfortunately, this made PHP quite unsuitable for me: While it is possible to write a socket server in PHP (ext/posix does exist), I never managed to get it to work as I wanted to. It was slow, unstable and created zombies.

Then I found RAGI which was even better. For quite some time now, I have been looking for an excuse to do something with Ruby on Rails. With RAGI, I finally got it.

Getting the sample provided with RAGI to work was very easy (look at the README file). And reading through that sample file, I was very pleased to see the simplicity of writing a AGI-Application in Ruby (RAGI uses FastAGI, of course).

Now I can finally start hacking away in Rails to create my internal-customer-database / external-phone-lookup application (with some nice caching/timeout handling) to finally show the name behind the calling phone number on the displays of our SNOM phones.

Of course I’m going to provide the sourcecode here once I’m done.

Strangest JavaScript error ever

Let’s say you create some very nice AJAX-stuff for a web project of yours. With nice I mean: Not breaking the back-button where its functionality is needed, not doing something that works better without AJAX, and doing it while providing lots of useful visual feedback.

Let’s further assume that the thing works like a charm in every browser out there (not counting Netscape 4.x and IE in all versions – those are no browsers).

And then, IE throws this at you:

Unknown Runtime Error

Needless to say that the HTML output in question had a line count not even close to 370, so finding this thing easily was out of the question.

The solution: IE is unable to write to innerHTML of a TBODY element. But instead of providing an useful error message or even a link to the source with the line in question already highlighted (that’s what Firefox would do), it just bails out with completely useless error information.

*sigh*

(btw: That mix of fonts in the details section of the error message is just another indication of IEs great code quality)

The myth of XCOPY deployment

Since the advent of .NET, everyone is talking about XCOPY deployment.

XCOPY deployment means that the applications are distributabe without a setup routine. Just copy the file(s) where you want them and that’s it.

We are being told that this is much easier and safer than the previous non-.NET approaches which – as they continue – always required a setup program.

The problem with those statements is that they are all false.

First the ease of use: Think of it: Say you want to install Cropper (which made me write this entry. I found that screenshot utility via flow|state). What you are getting is a ZIP-File, containing 5 files and a folder (containing another 6 files). Nearly all the files are needed for the application to run.

XCOPY deployment in this case means: Create a folder somewhere (Windows guidelines advocate you create that in c:Program Files which is a folder windows does not want you to mess with and per default does not display its contents) and copy over all those files, being aware not to forget a file or the folder in the archive.

But it does not end there: As you have to launch the application and going all the way through those folders, you will want to have a shortcut in the start menu or on the desktop. With this new and “better” method of deployment, you’ll have to do that yourself.

This is a tedious task involving lots of clicks and browsing. An unexperienced user may not be able to do this at all.

What an unexperienced user will want to do is to copy that application right to the desktop. But in this case this does not work well as the whole application consits of multiple interdependant parts. Copying only the .EXE will break the thing.

Compare this with Mac OS X

In Mac OS X, application also consist of multiple parts. But the shell is built with XCOPY deployment (not called like this, of course. As a matter of fact, it does not have a name at all) in mind: In OS X, you can create a special kind of folder which is a folder only on the file system. The shell displays it to the user as a single file – the application.

Whenever you move that “file” around, OS X will move the whole folder. When you double click the “file”, the application will launch (the binary is a file somewhere in this special folder. The shell is intelligent enough to find and launch that). When you delete it, the shell will delete the folder including it’s contents (of course).

This makes XCOPY deployment possible as the applications become one piece. You want it on the desktop? Drag it there. In the Application folder (without warnings about not being allowed to mess with its contents, btw)? Drag it there? On an USB-Stick? Drag it there.

Well. There’s one other thing: It’s the users data and the applications data. Most of the applications will be used to create data with them. And all application somehow create their own data (for saving things like the window state or position for example). As all modern OSes are multiuser ones where a user does not necessarily have to have write access everywhere, there’s the concept of the home directory. That one is yours. You may store whatever you want in there.

So naturally, this is the place where the applications should store data to0.

User data goes to a specific folder of the users choice. Per default, applications should suggest some Documents-Folder. Like “My Documents” in Windows or “Documents” in Mac OS. In most of the cases you don’t want to delete that on uninstall.

Application settings are in Windows stored in the Registry (under HKEY_CURRENT_USER – a hive that belongs to the current user like his home folder does. And actually, the file behind that is stored in the home folder aswell (USER.DAT)) or in the Application Data folder below the users home folder.

Mac OS X Applications are advised to use the Preferences-Folder inside the Library Folder inside the users home directory<./p>

Now. Application data is something you want to remove when you uninstall the application (which means deleting a bunch of files in Windows or one “File” in Mac OS). Application data is created by the application, for the application. No need to keep that.

In Mac OS, you can do that by going into the folder I’ve described above and delete the files – mostly named after your application. There are no warnings, no questions, no nothing. Just delete.

In Windows, editing the registry is off-limits for end-users and very, very tedious to do for experienced users (due to the suboptimal interface of regedit and because the whole thing is just too large to navigate it easily), so you generally let the stuff stick there. Deleting the Application Data in the same-named folder is also impossible for the end user: That folder is hidden by default. Explorer does not display it. And it’s hard as hell to find, as you have to manually navigate into your home directory – there’s not easy GUI-access to that. So that sticks too.

All in all, this means that windows is – at least in its current state – very unsuited for XCOPY deployment:

  • It does not help at keeping together things that must be together
  • Its complex file system structure makes it hard to copy the application where windows wants it to be
  • Manually creating shortcuts is not feasible for an unexperienced user
  • Uninstallation of Application Data is impossible

So, we found out that XCOPY deployment is not easy at all. Now let’s find out how it’s not true that only .NET enabled you to do this.

Ever since there is Delphi, there theoretically is XCOPY deployment.

Delphi is very good at creating self-contained executables.

With delphi it’s a breeze to create one single .EXE containing all the functionality you need. That one single .EXE can be moved around as a whole (obviously), can be deleted, can even be put right into the start menu (if you want that). It can even create the start menu shourcuts, delete application data – basically configure and clean itself

It can even uninstall itself (embed an uninstaller, launch that with CreateProcess and set the flag to delete the .exe after it ran). And it can contain all it’s image and video and sound data it needs.

Just because nobody did it does not mean it was not possible.

Face it: Windows users are used to fancy installers. Windows users are not at all used to dragging and dropping an application somewhere. And currently Windows users are not even able to do so as dragging and dropping will break the application.

OS X and now Linux allow for true XCOPY deployment of desktop applications.

Well, you say… then maybe XCOPY deployment is just for those fancy ASP.NET web applications?

Maybe. But after XCOPY you need to configure your webserver – at least create a virtual directory or host. A good installer could do that for you – if you want it to.

Microsoft too has seen that this XCOPY thingie is not as great as everyone expected, so they added the new “One-Click Install” technology, which is not much more than a brushed-up MSI file which does a old-fashioned install.

To really make XCOPY deployment a reality (btw, I’m a big fan of depolying software like this), there must be some changes within Windows itself. Microsoft, copy that application bundle feature from OSX. That one works really, really good.

Btw: Am I the only one that thinks “XCOPY deployment” is a very bad term? What is XCOPY? Who the hell still uses XCOPY these days? And when we are using the command line: COPY would be enough.

PostgreSQL scales

Via zillablog, I was notified of FeedLounge switching to PostgreSQL

FeedLounge is just another in a serious of webbased services switching their RDBMS away from MySQL.

For one thing, it’s the features that’s driving this. Postgres just has more features and sometimes, you need to have them. Triggers? Views? Until very recently, those features were not available with MySQL.

And when they switch, they notice another thing: PostgreSQL scales very well.

While everyone says that MySQL is optimized for speed and that there’s no database system as fast as MySQL, this is only true for small setups.

In small setups MySQL scores with its ease of use and administration. But as soon as you want more (more features, more users accessing), you will run into MySQL’s limitations and – even more important: MySQL will slow down, it will use lots of RAM and disk space and it even will begin to corrupt it’s tables (a thing a RDBMS should never ever do – not even in case of broken hardware though that’s unavoidable).

PostgreSQL does not have these flaws. It may be a little bit slower under low load, but it speed and reliability scales with its users.

PostgreSQL scales.

Opera Mini

Today, Opera released Opera Mini, a browser written in Java for all the Java capable mobile phones out there

By the use of a special proxy server, they manage to both minimize the traffic a usual browsing session generates and to keep the application as performant as possible.

When I tried to download the application via WAP, all I got was an ‘Invalid Jad Request’-Error (wahtever that meant), but with some sneakyness, I found the download URL for the jar file none the less (the linked version is the high-memory version. There’s another for less advanced phones)

I copied the file over to my K750i via bluetooth which is cheaper than downloading it and it also had the advantage of actually working.

The browser is very nice. While it uses quite some time to finally launch, surfing is very quick. And the very good font rendering (of course operas small screen rendering is active aswell) makes this a pleasure to use and is the first justification why a phone should have a screen resolution as big as the K750i’s

And the most interesting thing: Opera uses the default internet GPRS profile. Not the WAP one. This makes surfing via opera a whole lot cheaper than via the built-in wap browser of my phone.

Congratulations, Opera. This rules!

(and thanks, Christoph, for pointing it out to me)

PostgreSQL 8.1

A new year, a new announcement of a new version of PostgreSQL, an all-time-member on my favourite tools list.

2002 brought us PostgreSQL 7.3, 2003 brought 7.4 (no announcement on this blog) and 2004 brought us PostgreSQL 8.0 (the date of the blog entries match out of sheer accident – I did not time them at all).

And now it’s time for the next announcement. While the team is a bit early this time (it’s not december the 2nd yet), it once more brings a lot of good stuff.

What’s the most interesting aspect about those PostgreSQL releases: They always bring just the feature I need at the time of the release.

7.1 brought TOAST tables. 7.4 brought autovacuum, 8.0 brought the windows version and now 8.1 brought some needed performance improvements with large tables and large COPY operations (which is what I’m doing currently)

And it’s not just me. Christoph was in the position to have needed something like PHP’s max() function. And what do we learn: 8.1 brings us greatest()

Congratulations to another splendid release, PostgreSQL team. I hope to see you going as strong for the next couple of years.

Usability with the Browse for folder dialog

browsefolder.png

This dialog is the worst usability nightmare ever. It’s so bad that I’m really afraid of using any function in any program making me to chose a directory. Why? Don’t get me started:

  • It’s too small. Newer versions of Windows allow you to resize it, but it’s dependent on the program. The one I took this screenshot off does not.
  • It’s uncommon. You don’t see that dialog often. Many programs use a standard file selection dialog when they ask for a directory (I guess because of the problems outlined here)
  • It does not allow multiple selection. Meaning that if your program provides the user to work with multiple directories at once, it can’t be done with this dialog. You have to build your own solution, thus losing even more usability by forcing the user to learn something new
  • The tree-view is an uncommon view on the filesystem. Over time, Microsoft eliminated the tree view for directory navigation more and more. You have to willingly turn it on in Windows XP. There’s no explorer view with that tree per default
  • It’s context-less. Tell me: What’s the reason to select a folder in the dialog you see in the screenshot above? I don’t select a folder for the selections sake. I want do do something with that folder. What? The dialog does not tell me. I know this can be set in the API-Call to bring up the dialog. But many people do not.
  • It has not way to enter a path manually. Copy & Paste exists for a reason. If you have deeply nested paths, it can be a real timesaver. Navigate in Explorer (maybe already open anyways), Copy the path to the clipboard and… nope… no pasting
  • It has no autocomplete. I’m very fast in typing paths with the help of autocomplete: c:Pro[arrow down]Po[arrow down] and I’m in c:Program FilesPopScan. Not in this dialog. In this dialog, I have to click through the whole path
  • Around Windows 2000, microsoft extended the file selection dialogs with a shortcut bar allowing easy access to some commonly used folders. This bar is missing in this dialog.
  • It’s readonly. What if I want to make a new folder? Some “editions” of the dialog do provide a ‘New Folder’ button. Even so, it works by adding a ‘New Folder’-Folder and you have to manually click it to rename it (at least on this system here. Behaviour is erratic
  • There’s no context menu. Usuall when you see filesystem icons, you can right-click it to get a systemwide context-menu. Not with this dialog. Well. You can right-click. A context menu does appear. But the single entry is “What’s this” providing an utterly pointless context sensitive help entry that – I’m afraid has no context at all: “Click the plus sign (+) to display more choices” choices? What choices? Why do I want to see new choices? This is no answer for the question “what’s this”. It’s no answer at all. What the heck.
  • It’s context less (yeah. we had that before): Tell me: What’s the path I currently have selected in the screenshot? How can I know I have selected the correct folder? I may – after all – have multiple Richard Wagner folders on my harddrive
  • I wanted to write that it violates fitts law because you had to click those small ‘+’-signs (as the context sensitive help tells you). And now – after years of using this dialog I finally learned that you can double-click folders to expland them. I did not know that until now
  • When you have mounted network drives, it’s a living performance-problem as the top layer of the dialog displays all drives which can take some time. In which the dialog (and the unerlying app freezes).
  • The deeper you get in the hierarchy, the more you have to horizontally scroll.

I’m sure I can list even more, but enough is enough. I’m sure you get the point

Microsoft, I beg of you: Redesign this dialog!

Force the programs to use the new design. Don’t provide a fallback!

This way only the programs that are actually re-building this dialog (instead of calling the API) remain broken – and after all, they were broken to begin with: Why rebuild something crappy? Why rebuild it and risk it only being similar but not identical in usage? Why rebuild and risk it remaining broken even if the dialog gets fixed?

And believe me: There are people rebuilding existing OS-features. For no reason at all (see another posting about Adobes new file selection dialogs)

Frustrated by personal firewalls

As you may know, the company I’m working in develops barcode ordering solutions.

Now for me it’s very frustrating to see that whatever I do, those oh-so-good personal firewall and internet security and whatnot tools manage to screw the experience for the enduser. During developement, I’m always watching to adhere to common known-good practices in regards to handling the system. Works without admin rights? Yes. Uses systemwide functions wherever possible? Yes. Clean uninstall? Yes. Spyware free? Of course. Trojan horse? God beware! No!

None the less, PopScan gets majorly screwed here and then:

  • Norton Internet Security is per default configured to let only ‘Programs authorized by Symantec’ to access the internet. I don’t even try to ask how to get on that list – besides the fact that we’d never have the resources to do wahtever Symantec wants from us – if they provide such a possibility at all.
  • Whenever the offline version connects to the internet, a big scary warning from whatever personal firewall (besides Norton – that tool silently blocks everything that’s not IE and LiveUpdate) pops up telling the (not-knowing) user that something bad is currently happening. End-users are known to click ‘block’ here and accuse us of creating trojan horses
  • To circumvent many problems associated with installations on the client, we created the Web version of PopScan. And you know what: We’re still screwed. Java-Applets get blocked (how the hell should we get the barcodes in the scanner if not with Java or ActiveX??), PopUps get blocked (of course we don’t pop up any unrequested ones. The only popup used is for reading the scanner. With onClick=”window.open()”. It can’t be more ‘user-requested’ than this. Still… Some security program deemed it necessary to block that.

The worst thing about all that is: Those obviously broken programs that screw applications all over the place call themselves ‘Security Tools’ and with this, they seem to be automatically trusted by the end users. If a security tool tells the user “Trojan Horse Alert”, the user panics and blocks everyting. If a security tool just silently blocks certain internet connections (PopScan Offline uses Port 80 to communicate – using WinInet API – a less intrusive, less sneaky way for connecting to the internet does not exist), everyone blames the blocked program of not working.

To connect to the internet regardless of any PFW setting would mean to inject code into IE and use that to do your internet work. The better tools still detect that, but you can get around it by abusing the Windows Message Loop and simulating keypresses. But both solutions are actually trojany. And I’d never ever implement such a “feature”. It’s compomising stability and integrity. And it’s etically flawed. None the less: The tools force me to do something like this if I want to work it 100% of the caused in 100% of the installations

Those tools go way too far.

And don’t forget: It’s the nonexperienced users that get bitten: Those install security tools. Those don’t know what those tools do. Those trust them. Those make the wrong conclusions (PopScan can’t connect. PopScan must be broken).

It’s just frustrating. Why use lots of time to make a software non-intrusive and perfectly compliant to both technical and ethical standards when it’s blocked just like your average trojan horse trashing your installation and displaying advertisement all over the place?

Actually I think, those trojans are better off because they have code to circumvent the security tools.

As it currently stands I have the feeling these tools do block more legitimate applications then trojan horses. And this frustrates me. Greatly.

On the search of a text editor

When I began with this blog, I was using jEdit because of its wonderful list of countless features directly optimized for the programmers needs.

It was lacking one thing though: PHP support. While it provides (excellent) syntax highlighting, there’s nothing more. No code completition, no parameter hints, no code browser. While many people tick those things off as useful but not needed, I tend to disagree:

Sometime around autumn 2003, I gave the Zend Studio another try. And it has matured quite a lot since its first release. The speed problems were fixed, some editing features came back… nice.

What made me stick to Zend Studio is the above features: Code completition and parameter hints.

I know that you can just look the order of a functions parameter up in either your (or someone elses) code or in the manual, but it always interrupts your work. Not only that, you have to actually know where to look. Is it in the PHP manual? In code file a? In file b? Maybe in some library installed in /usr/lib/php (PEAR)? Zend Studio provides me with the parameter hints regardless of where the file is stored – provided it can read them.

This is a killer-feature. It immensely increases ones productivity. Whatever editor I’m ever going to use: It must have parameter-hinting for PHP. And it has to work as good as it does in the Zend IDE.

The Zend IDE has other problems though. What it has in parameter hinting, it lacks in basic editing features. Remove whitespace at the end of lines? Comment out a block? Smart autoindent (another thing where jEdit shines)? Splitting the editing window? No. Neither of them.

What pisses me off most (besides the whitespace problem as that creates very ugly SVN commits) is the font renedering though. Now that I finally found a font I really like, I’m unable to use it in the mostly used editor environement. Like many other Java applications Zend Studio does not support cleartype. And if you hack around a bit to run ZDE in a Java 1.6 alpha, the whole application will use cleartype – the whole application except the editing window, of course. Consolas looks really bad without ClearType.

Actually, any of the fonts I do like for programming (basically any besides Courier New) looks bad without ClearType, which means that I’m programming PHP with Courier as my font.

PHP of course is my main language at this time, so I’m doing most of my work in an environement that is not to my liking at all.

So… time for a new editor. Here’s what I’ve tried:

  • jEdit again. Now has a PHP parser plugin, which is completely unusable unfortunately: It parses while you are typing and as soon as it detects a syntax error (which is bound to happen while you are writing a line), it puts the keyboard focus to the error list(!!!!). This means that I have to type like this: function gnegg([TAB]$param1,[TAB]$param2){[TAB], the [TAB] meaning me hitting tab to get the focus back to where it belongs. Additionally, there’s no parameter hint, which is a must for me. As much as I’d like to use jEdit. It’s not possible like this. Sorry. (even though jEdit actually renders Consolas quite right with its own implementation of subpixel hinting).
  • PHPEclipse: An Eclipse plugin (even though Eclipse is written in Java, it uses SWT and thus the native font rendering of the underlying platform, meaning that cleartype is usable) teaching the JAVA IDE how to do PHP. Unfortunately, many of the great features in eclipse are part of the JDT plugin suite, so every language has to redo the stuff in there. PHPEclipse is seriously lacking in the features departement and the parameter completition is missing aswell.
  • UEStudio. Well… let’s try it with a commercial offering. UEStudio is a enhanced version of UltraEdit. They emphasize on their PHP support. You guessed right: No parameter hints.
  • phpEd, Maguma Studio, … I did not even try them again. My last experience was very, very painful. While Delphi is a RAD tool allowing to make quick progress, you have to be as careful with memory allocation as in every other native-compiled language. None of those Windows-Only-PHP-Editors seem to care about that, so they crash all the time. No alternative.

Well… that’s it for now. Please. Anyone! What are you working with? Is there a editor with the editing features of jEdit, the font rendering of eclipse and the PHP-specific features of Zend Studio (auto completition and parameter hinting)? I don’t need no profiler. No debugger. Just a good editor.

Am I doomed to write PHP with Courier New for the rest of my life?

Nice font…

I have my windows set up with ClearType™ enabled. Now, for Longhorn, they have created some new fonts, specially hinted for configurations with ClearType™ enabled. One of them – Consolas – has a fixed width and is for use in programming environements for exmple.

Sample Screenshot

I really like this font. It’s very easily readable but still looks great and smoothed.

Unfortunately, in environements without cleartype, it looks really crappy. One of those environements, unfortunately still is the Java Runtime and with this the Zend Studio. Actually, no single font i’ve tried in there looks acceptable. The best of them – still – is Courier New which is a real pain.

What I liked most about Consolas is also visible on the screenshot: Usually I’m working on a bright-on-dark editor scheme because it makes the thing a whole lot more readable for me. With consolas I don’t need this any more. The font looks good and readable even on a white background. This in turn takes away a lot of strain from my eyes.

Nice. I’ve copied it over from my Lonhorn VMware-Image to my default working-environement and I’m really, really happy