Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1753167485, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"948c7ace294b30b3844928d13495e594", "commit": {"type":"commit", "time": 1554823315, "time_ofs": 60, "oid_tree": { "oid": "c24792ba728ed1a899622b7cefb73370e80e5b8a", "alias": []}, "oid":{ "oid": "575b96e32e3a926bc9f56f15e865feaddf5c2abc", "alias": []}, "msg": "http: refactor and fixes in lws_get_mimetype", "sig_commit": { "git_time": { "time": 1554823315, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1554746612, "offset": 180 }, "name": "pavelxdd", "email": "pavel.otchertsov@gmail.com", "md5": "e1ac0b2881825960ee59b5922ab07ce7" }}, "body": "http: refactor and fixes in lws_get_mimetype\n\n- prioritize user-defined mimetypes over predefined server mimetypes.\n- fix accessing memory out of string bounds.\n- prefer case-insensitive comparison for extension matching.\n- other minor fixes and improvements.\n" , "diff": "diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c\nindex 5119762..29439f4 100644\n--- a/lib/roles/http/server/server.c\n+++ b/lib/roles/http/server/server.c\n@@ -378,75 +378,73 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername)\n \treturn NULL;\n }\n \n+static const struct lws_mimetype {\n+\tconst char *extension;\n+\tconst char *mimetype;\n+} server_mimetypes[] \u003d {\n+\t{ \u0022.html\u0022, \u0022text/html\u0022 },\n+\t{ \u0022.htm\u0022, \u0022text/html\u0022 },\n+\t{ \u0022.js\u0022, \u0022text/javascript\u0022 },\n+\t{ \u0022.css\u0022, \u0022text/css\u0022 },\n+\t{ \u0022.png\u0022, \u0022image/png\u0022 },\n+\t{ \u0022.jpg\u0022, \u0022image/jpeg\u0022 },\n+\t{ \u0022.jpeg\u0022, \u0022image/jpeg\u0022 },\n+\t{ \u0022.ico\u0022, \u0022image/x-icon\u0022 },\n+\t{ \u0022.gif\u0022, \u0022image/gif\u0022 },\n+\t{ \u0022.svg\u0022, \u0022image/svg+xml\u0022 },\n+\t{ \u0022.ttf\u0022, \u0022application/x-font-ttf\u0022 },\n+\t{ \u0022.otf\u0022, \u0022application/font-woff\u0022 },\n+\t{ \u0022.woff\u0022, \u0022application/font-woff\u0022 },\n+\t{ \u0022.woff2\u0022, \u0022application/font-woff2\u0022 },\n+\t{ \u0022.gz\u0022, \u0022application/gzip\u0022 },\n+\t{ \u0022.txt\u0022, \u0022text/plain\u0022 },\n+\t{ \u0022.xml\u0022, \u0022application/xml\u0022 },\n+\t{ \u0022.json\u0022, \u0022application/json\u0022 },\n+};\n+\n LWS_VISIBLE LWS_EXTERN const char *\n lws_get_mimetype(const char *file, const struct lws_http_mount *m)\n {\n-\tconst struct lws_protocol_vhost_options *pvo \u003d NULL;\n-\tint n \u003d (int)strlen(file);\n-\n-\tif (m)\n-\t\tpvo \u003d m-\u003eextra_mimetypes;\n-\n-\tif (n \u003c 5)\n-\t\treturn NULL;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.ico\u0022))\n-\t\treturn \u0022image/x-icon\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.gif\u0022))\n-\t\treturn \u0022image/gif\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 3], \u0022.js\u0022))\n-\t\treturn \u0022text/javascript\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.png\u0022))\n-\t\treturn \u0022image/png\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.jpg\u0022))\n-\t\treturn \u0022image/jpeg\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 3], \u0022.gz\u0022))\n-\t\treturn \u0022application/gzip\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.JPG\u0022))\n-\t\treturn \u0022image/jpeg\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 5], \u0022.html\u0022))\n-\t\treturn \u0022text/html\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.css\u0022))\n-\t\treturn \u0022text/css\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.txt\u0022))\n-\t\treturn \u0022text/plain\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.svg\u0022))\n-\t\treturn \u0022image/svg+xml\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.ttf\u0022))\n-\t\treturn \u0022application/x-font-ttf\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.otf\u0022))\n-\t\treturn \u0022application/font-woff\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 5], \u0022.woff\u0022))\n-\t\treturn \u0022application/font-woff\u0022;\n-\n-\tif (!strcmp(\u0026file[n - 4], \u0022.xml\u0022))\n-\t\treturn \u0022application/xml\u0022;\n+\tconst struct lws_protocol_vhost_options *pvo;\n+\tsize_t n \u003d strlen(file), len, i;\n+\tconst char *fallback_mimetype \u003d NULL;\n+\tconst struct lws_mimetype *mt;\n+\n+\t/* prioritize user-defined mimetypes */\n+\tfor (pvo \u003d m ? m-\u003eextra_mimetypes : NULL; pvo; pvo \u003d pvo-\u003enext) {\n+\t\t/* ie, match anything */\n+\t\tif (!fallback_mimetype \u0026\u0026 pvo-\u003ename[0] \u003d\u003d '*') {\n+\t\t\tfallback_mimetype \u003d pvo-\u003evalue;\n+\t\t\tcontinue;\n+\t\t}\n \n-\twhile (pvo) {\n-\t\tif (pvo-\u003ename[0] \u003d\u003d '*') /* ie, match anything */\n+\t\tlen \u003d strlen(pvo-\u003ename);\n+\t\tif (n \u003e len \u0026\u0026 !strcasecmp(\u0026file[n - len], pvo-\u003ename)) {\n+\t\t\tlwsl_info(\u0022%s: match to user mimetype: %s\u005cn\u0022, __func__, pvo-\u003evalue);\n \t\t\treturn pvo-\u003evalue;\n+\t\t}\n+\t}\n \n-\t\tif (!strcmp(\u0026file[n - strlen(pvo-\u003ename)], pvo-\u003ename))\n-\t\t\treturn pvo-\u003evalue;\n+\t/* fallback to server-defined mimetypes */\n+\tfor (i \u003d 0; i \u003c LWS_ARRAY_SIZE(server_mimetypes); ++i) {\n+\t\tmt \u003d \u0026server_mimetypes[i];\n \n-\t\tpvo \u003d pvo-\u003enext;\n+\t\tlen \u003d strlen(mt-\u003eextension);\n+\t\tif (n \u003e len \u0026\u0026 !strcasecmp(\u0026file[n - len], mt-\u003eextension)) {\n+\t\t\tlwsl_info(\u0022%s: match to server mimetype: %s\u005cn\u0022, __func__, mt-\u003emimetype);\n+\t\t\treturn mt-\u003emimetype;\n+\t\t}\n+\t}\n+\n+\t/* fallback to '*' if defined */\n+\tif (fallback_mimetype) {\n+\t\tlwsl_info(\u0022%s: match to any mimetype: %s\u005cn\u0022, __func__, fallback_mimetype);\n+\t\treturn fallback_mimetype;\n \t}\n \n \treturn NULL;\n }\n+\n static lws_fop_flags_t\n lws_vfs_prepare_flags(struct lws *wsi)\n {\n","s":{"c":1753167485,"u": 7583}} ],"g": 8759,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}