logo

What it does

URI Split does nothing more than split an URI string. It does that by searching the string for key characters like : and / in the URI. Once identified its parts (protocol, hostname, port, etc) URI Split fills in a struct with that information so you can retrieve the URI parts without parsing it again.

Installing/Upgrading

Installing URI Split it's really simple.

  1. Get the latest source code here
  2. Untar it somewhere and enter there
  3. Open the Makefile and check if there's something you'd want to change (mostly the PREFIX variable)
  4. Call make inside
  5. Become root with su (or sudo bash) and call make install

Coding with it

While URI Split was being (or is being) coded, I kept one single word in mind: simplicity. I was tired of the search for a library that was easy to use and small at the same time. I realized that if such library existed it was really hard to find, so I made it myself.

Here's a sample code:

#include <stdio.h>
#include <stdlib.h>
#include "urisplit.h"

int main(int argc, char ** argv) {
	if (argc < 2) return 0;
	struct spluri * inuri;
	char * string;

	inuri = urisplit(argv[1]);
	uriset(inuri, &inuri->username, "newusername");
	string = urijoin(inuri);

	printf("username: %s\n", inuri->username);
	printf("password: %s\n", inuri->password);
	printf("host: %s\n", inuri->host);
	printf("port: %s\n", inuri->port);
	printf("path: %s\n", inuri->path);
	printf("proto: %s\n", inuri->proto);

	printf("\nuri: %s\n", string);
	free(string);
	urifree(inuri);
	return 0;
}
			

Now we must compile it:

gcc uri.c -o uri -lurisplit