#include <fcntl.h>
#include <sys/socket.h>
+#ifndef PATH_MAX
+# define PATH_MAX 255
+#endif
+
#define nghttp3_arraylen(A) (sizeof(A) / sizeof(*(A)))
/* The crappy test wants 20 bytes */
int received_from_two; /* workaround for -607 on nghttp3_conn_read_stream on stream 2 */
int restart; /* new request/response cycle started */
uint64_t id_bidi; /* the id of the stream used to read request and send response */
+ char *fileprefix; /* prefix of the directory to fetch files from */
char url[MAXURL]; /* url to serve the request */
uint8_t *ptr_data; /* pointer to the data to send */
unsigned int ldata; /* amount of bytes to send */
}
}
-static int get_file_length(char *filename)
+static int get_file_length(struct h3ssl *h3ssl)
{
+ char filename[PATH_MAX];
struct stat st;
- if (strcmp(filename, "big") == 0) {
+ memset(filename, 0, PATH_MAX);
+ if (h3ssl->fileprefix != NULL)
+ strcat(filename, h3ssl->fileprefix);
+ strcat(filename, h3ssl->url);
+
+ if (strcmp(h3ssl->url, "big") == 0) {
printf("big!!!\n");
return INT_MAX;
}
return 0;
}
-static char *get_file_data(char *filename)
+static char *get_file_data(struct h3ssl *h3ssl)
{
- int size = get_file_length(filename);
+ char filename[PATH_MAX];
+ int size = get_file_length(h3ssl);
char *res;
int fd;
if (size == 0)
return NULL;
+ memset(filename, 0, PATH_MAX);
+ if (h3ssl->fileprefix != NULL)
+ strcat(filename, h3ssl->fileprefix);
+ strcat(filename, h3ssl->url);
+
res = malloc(size+1);
res[size] = '\0';
fd = open(filename, O_RDONLY);
nghttp3_conn *h3conn = NULL;
SSL *ssl;
+ h3ssl.fileprefix = getenv("FILEPREFIX");
+
/* Create a new QUIC listener. */
if ((listener = SSL_new_listener(ctx, 0)) == NULL)
goto err;
/* we have receive the request build the response and send it */
/* XXX add MAKE_NV("connection", "close"), to resp[] and recheck */
make_nv(&resp[num_nv++], ":status", "200");
- h3ssl.ldata = get_file_length(h3ssl.url);
+ h3ssl.ldata = get_file_length(&h3ssl);
if (h3ssl.ldata == 0) {
/* We don't find the file: use default test string */
sprintf(slength, "%d", 20);
} else {
/* normal file we have opened */
sprintf(slength, "%d", h3ssl.ldata);
- h3ssl.ptr_data = (uint8_t *) get_file_data(h3ssl.url);
+ h3ssl.ptr_data = (uint8_t *) get_file_data(&h3ssl);
if (h3ssl.ptr_data == NULL)
abort();
printf("before nghttp3_conn_submit_response on %llu for %s ...\n",
make_nv(&resp[num_nv++], "content-type", "image/png");
else if (strstr(h3ssl.url, ".ico"))
make_nv(&resp[num_nv++], "content-type", "image/vnd.microsoft.icon");
- else
+ else if (strstr(h3ssl.url, ".htm"))
make_nv(&resp[num_nv++], "content-type", "text/html");
+ else
+ make_nv(&resp[num_nv++], "content-type", "application/octet-stream");
+ make_nv(&resp[num_nv++], "content-length", slength);
}
dr.read_data = step_read_data;
for (;;) {
if (!hasnothing) {
- SSL *ssl = get_ids_connection(&h3ssl);
+ SSL *newssl = get_ids_connection(&h3ssl);
printf("hasnothing nothing WAIT %d!!!\n", h3ssl.close_done);
- if (ssl == NULL)
- ssl = listener;
- ret = wait_for_activity(ssl);
+ if (newssl == NULL)
+ newssl = listener;
+ ret = wait_for_activity(newssl);
if (ret == -1)
goto err;
if (ret == 0)