O'Reilly logo

Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 47. A Fast URL Router

Im now going to show you how I use the TSTree to do fast URL routing in Web servers that I’ve written. This works for simple URL routing that you might use at the edge of an application, but it doesn’t really work for the more complex (and sometimes unnecessary) routing found in many Web application frameworks.

To play with routing, I’m going to make a little command line tool that I’m calling urlor, which reads a simple file of routes, and then prompts the user to enter in URLs.

urlor.c

  1   #include <lcthw/tstree.h>   2   #include <lcthw/bstrlib.h>   3   4   TSTree *add_route_data(TSTree * routes, bstring line)   5   {   6       struct bstrList *data = bsplit(line, ' ');   7       check ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required