Added an initial implementation of HTTPS.
[ashd.git] / src / htparser.c
index 953ddac..4835549 100644 (file)
 
 static int plex;
 
+static void trimx(struct hthead *req)
+{
+    int i;
+    
+    i = 0;
+    while(i < req->noheaders) {
+       if(!strncasecmp(req->headers[i][0], "x-ash-", 6)) {
+           free(req->headers[i][0]);
+           free(req->headers[i][1]);
+           free(req->headers[i]);
+           memmove(req->headers + i, req->headers + i + 1, sizeof(*req->headers) * (--req->noheaders - i));
+       } else {
+           i++;
+       }
+    }
+}
+
 static struct hthead *parsereq(FILE *in)
 {
     struct hthead *req;
@@ -85,6 +102,7 @@ static struct hthead *parsereq(FILE *in)
     req = mkreq(method.b, url.b, ver.b);
     if(parseheaders(req, in))
        goto fail;
+    trimx(req);
     goto out;
     
 fail:
@@ -335,7 +353,7 @@ static void usage(FILE *out)
 {
     fprintf(out, "usage: htparser [-hSf] [-u USER] [-r ROOT] PORTSPEC... -- ROOT [ARGS...]\n");
     fprintf(out, "\twhere PORTSPEC is HANDLER[:PAR[=VAL][(,PAR[=VAL])...]] (try HANDLER:help)\n");
-    fprintf(out, "\tavailable handlers are `plain'.\n");
+    fprintf(out, "\tavailable handlers are `plain' and `ssl'.\n");
 }
 
 static void addport(char *spec)
@@ -370,6 +388,10 @@ static void addport(char *spec)
     /* XXX: It would be nice to decentralize this, but, meh... */
     if(!strcmp(nm, "plain")) {
        handleplain(pars.d, pars.b, vals.b);
+#ifdef HAVE_GNUTLS
+    } else if(!strcmp(nm, "ssl")) {
+       handlegnussl(pars.d, pars.b, vals.b);
+#endif
     } else {
        flog(LOG_ERR, "htparser: unknown port handler `%s'", nm);
        exit(1);
@@ -415,10 +437,6 @@ int main(int argc, char **argv)
            exit(1);
        }
     }
-    if((argc - optind) < 3) {
-       usage(stderr);
-       exit(1);
-    }
     s1 = 0;
     for(i = optind; i < argc; i++) {
        if(!strcmp(argv[i], "--"))