tAdd P and d types for documents - phroxy - Gopher to HTTP proxy
(HTM) git clone git://git.z3bra.org/phroxy.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit bccae5645b5b16cedf046c0d91a5faeb87287540
(DIR) parent bedd997f20b971eab551158ea6e61b0ec3c3d5d3
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Tue, 25 Oct 2022 12:38:56 +0200
Add P and d types for documents
Diffstat:
M phroxy.c | 47 +++++++++++++++++++++----------
1 file changed, 32 insertions(+), 15 deletions(-)
---
(DIR) diff --git a/phroxy.c b/phroxy.c
t@@ -29,6 +29,8 @@ enum {
ITEM_g,
ITEM_h,
ITEM_s,
+ ITEM_P,
+ ITEM_d,
};
#include "config.h"
t@@ -225,37 +227,47 @@ printhttp(int code)
char *
contenttype(char i, char *path)
{
- static char *ext, type[12];
+ static char *ext, type[32];
+
+ /* isolate file extention, if any */
+ ext = strrchr(path, '.');
+ ext = ext ? ext + 1 : "*";
switch(i) {
case '0':
case '1':
case '7':
case 'h':
- return "text/html; charset=utf-8";
- break; /* NOTREACHED */
+ snprintf(type, sizeof(type)-1, "text/html; charset=utf-8");
+ break;
case '6':
- return "text/x-uuencode";
- break; /* NOTREACHED */
+ snprintf(type, sizeof(type)-1, "text/x-uuencode");
+ break;
case '4':
case '5':
case '9':
- return "application/octet-stream";
- break; /* NOTREACHED */
+ snprintf(type, sizeof(type)-1, "application/octet-stream");
+ break;
case 'I':
- if (!(ext = strrchr(path, '.')))
- return "image/*";
-
/* assume 4 chars max for extension */
- snprintf(type, 11, "image/%s", ext + 1);
- return type;
- break; /* NOTREACHED */
+ snprintf(type, sizeof(type)-1, "image/%s", ext);
+ break;
+ case 's':
+ snprintf(type, sizeof(type)-1, "audio/%s", ext);
+ break;
case 'g':
- return "image/gif";
+ snprintf(type, sizeof(type)-1, "image/gif");
+ break;
+ case 'P':
+ case 'd':
+ snprintf(type, sizeof(type)-1, "application/%s", ext);
+ break;
+ default:
+ return NULL;
break; /* NOTREACHED */
}
- return NULL;
+ return type;
}
const char *
t@@ -276,6 +288,8 @@ itemname(char i)
case 'g': return items[ITEM_g];
case 'h': return items[ITEM_h];
case 's': return items[ITEM_s];
+ case 'd': return items[ITEM_d];
+ case 'P': return items[ITEM_P];
}
return NULL;
t@@ -416,6 +430,9 @@ serveitem(char item, char *path, char *data, size_t len)
case '9': // binary
case 'g': // gif
case 'I': // image
+ case 's': // sound
+ case 'd': // document
+ case 'P': // pdf (~document)
case 'h': // http redirect
printf("Content-Length: %ld\r\n", len);
printf("\r\n");