]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
port the 2 improvement suggested by @nhorman to help to run the
authorJean-Frederic Clere <jfclere@gmail.com>
Mon, 9 Dec 2024 13:32:28 +0000 (14:32 +0100)
committerNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 16:27:33 +0000 (11:27 -0500)
quic-interop-runner.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25859)

demos/http3/ossl-nghttp3-demo-server.c

index 87b9cdc35a975c3ceadb9f3143eea6778598d114..1744e64c01fcd91d39aca98445335878c34c869c 100644 (file)
 #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 */
@@ -58,6 +62,7 @@ struct h3ssl {
     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 */
@@ -718,11 +723,17 @@ static void handle_events_from_ids(struct h3ssl *h3ssl)
     }
 }
 
-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;
     }
@@ -737,15 +748,21 @@ static int get_file_length(char *filename)
     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);
@@ -992,6 +1009,8 @@ static int run_quic_server(SSL_CTX *ctx, int fd)
     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;
@@ -1101,7 +1120,7 @@ static int run_quic_server(SSL_CTX *ctx, int fd)
         /* 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);
@@ -1117,7 +1136,7 @@ static int run_quic_server(SSL_CTX *ctx, int fd)
         } 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",
@@ -1126,8 +1145,11 @@ static int run_quic_server(SSL_CTX *ctx, int fd)
                 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;
@@ -1203,11 +1225,11 @@ static int run_quic_server(SSL_CTX *ctx, int fd)
         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)