Skip to content

Instantly share code, notes, and snippets.

@aleks-mariusz
Last active August 29, 2015 14:00
Show Gist options
  • Save aleks-mariusz/041b8533585274ddf121 to your computer and use it in GitHub Desktop.
Save aleks-mariusz/041b8533585274ddf121 to your computer and use it in GitHub Desktop.
Nov 20 2001 - I fell in love with regular expressions pretty early on (before i knew how expensive they could be).. Here is some side work i did on a really ancient web server that was choking up trying to serve requests handled by perl, required me to dig deep in my coding knowledge and muster up this C code (because compiled code usually is ty…
#include <stdio.h>
#include <pcre.h>
int main() {
pcre *re; pcre_extra *extra = NULL;
char *httpHost; const char *error; const char **stringlist;
int offsets[45]; int offsetsSize = sizeof(offsets)/sizeof(int);
int erroroffset, count, start_offset;
re = pcre_compile("^([^.]+\\.)?([^.]+)\\.(...?)$", 0, &error, &erroroffset, NULL);
httpHost = getenv("HTTP_HOST");
count = pcre_exec(re, extra, httpHost, strlen(httpHost), 0, 0, offsets, offsetsSize);
(void)pcre_get_substring_list(httpHost, offsets, count, &stringlist);
strcpy(httpHost,stringlist[2]);
printf("Status: 302 Moved\nLocation: http://apps5.oingo.com/apps/domainpark/domainpark.cgi?s=%s&cid=GOTO0544&dp_p4pid=netincomeventures&dp_lp=6&dp_email=chernoff@netincome.com&dp_format=1.3\n",httpHost);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment