PoundでProxyPassディレクティブみたいなことをやる

requestとheaders[0]を書き換えて「/」を「/local/」にディスパッチ。
つーか、置換やってくれる正規表現ライブラリが欲しいなぁ。

--- http.c.orig	2008-02-11 15:00:11.203125000 +0900
+++ http.c	2008-02-11 15:30:22.859375000 +0900
@@ -436,6 +436,17 @@ log_bytes(char *res, const long cnt)
     if(ssl != NULL) { ERR_clear_error(); ERR_remove_state(0); } \
 }
 
+static void dispatch(char *path, int len, int offset, char *request) {
+  int i;
+
+  for (i = MAXBUF - len; i >= offset; i--) {
+    request[i + len] = request[i];
+  }
+
+  strncpy(request + offset, path, len);
+  request[MAXBUF - 1] = '\0';
+}
+
 /*
  * handle an HTTP request
  */
@@ -577,9 +588,18 @@ thr_http(void *arg)
             clean_all();
             pthread_exit(NULL);
         }
+
+        char *path = "local/";
+        int len = 6;
+        dispatch(path, len, matches[2].rm_eo, headers[0]);
+        dispatch(path, len, matches[2].rm_eo, request);
+
         cl_11 = (request[strlen(request) - 1] == '1');
-        strncpy(url, request + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
-        url[matches[2].rm_eo - matches[2].rm_so] = '\0';
+        strncpy(url, request + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so + len);
+        url[matches[2].rm_eo - matches[2].rm_so + len] = '\0';
+        // XXX: debug
+        fprintf(stderr, "req: %s\n", request);
+        fprintf(stderr, "url: %s\n", url);
         if(lstn->has_pat && regexec(&lstn->url_pat,  url, 0, NULL, 0)) {
             addr2str(caddr, MAXBUF - 1, &from_host);
             logmsg(LOG_NOTICE, "bad URL \"%s\" from %s", url, caddr);