diff options
author | Christian Hesse <mail@eworm.de> | 2014-04-22 13:57:51 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2014-04-22 13:57:51 +0200 |
commit | 1c9cc347b096b2536b229ef0e0d1551090e8ed70 (patch) | |
tree | e5130d0cbd55dc13e2fa35e3fce465c53076d739 | |
parent | 2790f410b553d63965b654a3248cbff51121e5e3 (diff) | |
download | pacredir-1c9cc347b096b2536b229ef0e0d1551090e8ed70.tar.gz pacredir-1c9cc347b096b2536b229ef0e0d1551090e8ed70.tar.zst |
redirect to project website if no file is given
-rw-r--r-- | config.def.h | 3 | ||||
-rw-r--r-- | pacredir.c | 9 |
2 files changed, 12 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index ce0c142..d439350 100644 --- a/config.def.h +++ b/config.def.h @@ -8,6 +8,9 @@ #ifndef _CONFIG_H #define _CONFIG_H +/* website url */ +#define WEBSITE "https://github.com/eworm-de/paccache/" + /* This is used for default documents. Usually you will not see this anyway. */ #define PAGE307 "<html><head><title>307 temporary redirect</title>" \ "</head><body>307 temporary redirect: " \ @@ -333,6 +333,14 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char * /* clear context pointer */ *ptr = NULL; + /* redirect to website if no file given */ + if (*basename == 0) { + http_code = MHD_HTTP_OK; + /* duplicate string so we can free it later */ + url = strdup(WEBSITE); + goto response; + } + /* process db file (and signature) request */ if ((strlen(basename) > 3 && strcmp(basename + strlen(basename) - 3, ".db") == 0) || (strlen(basename) > 7 && strcmp(basename + strlen(basename) - 7, ".db.sig") == 0)) { @@ -417,6 +425,7 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char * free(request); } +response: /* give response */ if (http_code == MHD_HTTP_OK) { write_log(stdout, "Redirecting to %s\n", url); |