Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1571532764, "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":"c4202591292b7488839429f1a365d919", "oid":{ "oid": "b7a04a67d15efd0f17bf795b8d3648425b604581", "alias": [ "refs/heads/master"]},"blobname": "minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c", "blob": "/*\n * lws-minimal-http-server-multivhost\n *\n * Written in 2010-2019 by Andy Green \u003candy@warmcat.com\u003e\n *\n * This file is made available under the Creative Commons CC0 1.0\n * Universal Public Domain Dedication.\n *\n * This demonstrates the most minimal http server you can make with lws.\n *\n * To keep it simple, it serves stuff from the subdirectory \n * \u0022./mount-origin\u0022 of the directory it was started in.\n * You can change that by changing mount.origin below.\n */\n\n#include \u003clibwebsockets.h\u003e\n#include \u003cstring.h\u003e\n#include \u003csignal.h\u003e\n\nstatic int interrupted;\n\nstatic const struct lws_http_mount mount_localhost1 \u003d {\n\t/* .mount_next */\t\tNULL,\t\t/* linked-list \u0022next\u0022 */\n\t/* .mountpoint */\t\t\u0022/\u0022,\t\t/* mountpoint URL */\n\t/* .origin */\t\t\t\u0022./mount-origin-localhost1\u0022,\n\t/* .def */\t\t\t\u0022index.html\u0022,\t/* default filename */\n\t/* .protocol */\t\t\tNULL,\n\t/* .cgienv */\t\t\tNULL,\n\t/* .extra_mimetypes */\t\tNULL,\n\t/* .interpret */\t\tNULL,\n\t/* .cgi_timeout */\t\t0,\n\t/* .cache_max_age */\t\t0,\n\t/* .auth_mask */\t\t0,\n\t/* .cache_reusable */\t\t0,\n\t/* .cache_revalidate */\t\t0,\n\t/* .cache_intermediaries */\t0,\n\t/* .origin_protocol */\t\tLWSMPRO_FILE,\t/* files in a dir */\n\t/* .mountpoint_len */\t\t1,\t\t/* char count */\n\t/* .basic_auth_login_file */\tNULL,\n}, mount_localhost2 \u003d {\n\t/* .mount_next */\t\tNULL,\t\t/* linked-list \u0022next\u0022 */\n\t/* .mountpoint */\t\t\u0022/\u0022,\t\t/* mountpoint URL */\n\t/* .origin */\t\t\t\u0022./mount-origin-localhost2\u0022,\n\t/* .def */\t\t\t\u0022index.html\u0022,\t/* default filename */\n\t/* .protocol */\t\t\tNULL,\n\t/* .cgienv */\t\t\tNULL,\n\t/* .extra_mimetypes */\t\tNULL,\n\t/* .interpret */\t\tNULL,\n\t/* .cgi_timeout */\t\t0,\n\t/* .cache_max_age */\t\t0,\n\t/* .auth_mask */\t\t0,\n\t/* .cache_reusable */\t\t0,\n\t/* .cache_revalidate */\t\t0,\n\t/* .cache_intermediaries */\t0,\n\t/* .origin_protocol */\t\tLWSMPRO_FILE,\t/* files in a dir */\n\t/* .mountpoint_len */\t\t1,\t\t/* char count */\n\t/* .basic_auth_login_file */\tNULL,\n}, mount_localhost3 \u003d {\n\t/* .mount_next */\t\tNULL,\t\t/* linked-list \u0022next\u0022 */\n\t/* .mountpoint */\t\t\u0022/\u0022,\t\t/* mountpoint URL */\n\t/* .origin */\t\t\t\u0022./mount-origin-localhost3\u0022,\n\t/* .def */\t\t\t\u0022index.html\u0022,\t/* default filename */\n\t/* .protocol */\t\t\tNULL,\n\t/* .cgienv */\t\t\tNULL,\n\t/* .extra_mimetypes */\t\tNULL,\n\t/* .interpret */\t\tNULL,\n\t/* .cgi_timeout */\t\t0,\n\t/* .cache_max_age */\t\t0,\n\t/* .auth_mask */\t\t0,\n\t/* .cache_reusable */\t\t0,\n\t/* .cache_revalidate */\t\t0,\n\t/* .cache_intermediaries */\t0,\n\t/* .origin_protocol */\t\tLWSMPRO_FILE,\t/* files in a dir */\n\t/* .mountpoint_len */\t\t1,\t\t/* char count */\n\t/* .basic_auth_login_file */\tNULL,\n};\n\nvoid sigint_handler(int sig)\n{\n\tinterrupted \u003d 1;\n}\n\nvoid vh_destruction_notification(struct lws_vhost *vh, void *arg)\n{\n\tlwsl_user(\u0022%s: called, arg: %p\u005cn\u0022, __func__, arg);\n}\n\nint main(int argc, const char **argv)\n{\n\tstruct lws_context_creation_info info;\n\tstruct lws_context *context;\n\tconst char *p;\n\tint n \u003d 0, logs \u003d LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE\n\t\t\t/* for LLL_ verbosity above NOTICE to be built into lws,\n\t\t\t * lws must have been configured and built with\n\t\t\t * -DCMAKE_BUILD_TYPE\u003dDEBUG instead of \u003dRELEASE */\n\t\t\t/* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */\n\t\t\t/* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */\n\t\t\t/* | LLL_DEBUG */;\n\n\tif ((p \u003d lws_cmdline_option(argc, argv, \u0022-d\u0022)))\n\t\tlogs \u003d atoi(p);\n\n\tlws_set_log_level(logs, NULL);\n\tlwsl_user(\u0022LWS minimal http server-multivhost | visit http://localhost:7681 / 7682\u005cn\u0022);\n\n\tsignal(SIGINT, sigint_handler);\n\n\tmemset(\u0026info, 0, sizeof info); /* otherwise uninitialized garbage */\n\tinfo.options \u003d LWS_SERVER_OPTION_EXPLICIT_VHOSTS |\n\t\tLWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;\n\n\t/*\n\t * Because of LWS_SERVER_OPTION_EXPLICIT_VHOSTS, this only creates\n\t * the context and no longer creates a default vhost\n\t */\n\tcontext \u003d lws_create_context(\u0026info);\n\tif (!context) {\n\t\tlwsl_err(\u0022lws init failed\u005cn\u0022);\n\t\treturn 1;\n\t}\n\n\t/* it's our job now to create the vhosts we want:\n\t *\n\t * - \u0022localhost1\u0022 listen on 7681 and serve ./mount-origin-localhost1/\n\t * - \u0022localhost2\u0022 listen on 7682 and serve ./mount-origin-localhost2/\n\t * - \u0022localhost3\u0022 share 7682 and serve ./mount-origin-localhost3/\n\t *\n\t * Note lws supports dynamic vhost creation and destruction at runtime.\n\t * When using multi-vhost with your own protocols, you must provide a\n\t * pvo for each vhost naming each protocol you want enabled on it.\n\t * minimal-ws-server-threads demonstrates how to provide pvos.\n\t */\n\n\tinfo.port \u003d 7681;\n\tinfo.mounts \u003d \u0026mount_localhost1;\n\tinfo.error_document_404 \u003d \u0022/404.html\u0022;\n\tinfo.vhost_name \u003d \u0022localhost1\u0022;\n\n\tif (!lws_create_vhost(context, \u0026info)) {\n\t\tlwsl_err(\u0022Failed to create first vhost\u005cn\u0022);\n\t\tgoto bail;\n\t}\n\n\tinfo.port \u003d 7682;\n\tinfo.mounts \u003d \u0026mount_localhost2;\n\tinfo.error_document_404 \u003d \u0022/404.html\u0022;\n\tinfo.vhost_name \u003d \u0022localhost2\u0022;\n\n\tif (!lws_create_vhost(context, \u0026info)) {\n\t\tlwsl_err(\u0022Failed to create second vhost\u005cn\u0022);\n\t\tgoto bail;\n\t}\n\n\t/* a second vhost listens on port 7682 */\n\tinfo.mounts \u003d \u0026mount_localhost3;\n\tinfo.error_document_404 \u003d \u0022/404.html\u0022;\n\tinfo.vhost_name \u003d \u0022localhost3\u0022;\n\tinfo.finalize \u003d vh_destruction_notification;\n\tinfo.finalize_arg \u003d NULL;\n\n\tif (!lws_create_vhost(context, \u0026info)) {\n\t\tlwsl_err(\u0022Failed to create third vhost\u005cn\u0022);\n\t\tgoto bail;\n\t}\n\n\tif (lws_cmdline_option(argc, argv, \u0022--die-after-vhost\u0022)) {\n\t\tlwsl_warn(\u0022bailing after creating vhosts\u005cn\u0022);\n\t\tgoto bail;\n\t}\n\n\twhile (n \u003e\u003d 0 \u0026\u0026 !interrupted)\n\t\tn \u003d lws_service(context, 0);\n\nbail:\n\tlws_context_destroy(context);\n\n\treturn 0;\n}\n","s":{"c":1571532764,"u": 333}} ],"g": 1374,"chitpc": 0,"ehitpc": 0, "indexed":0 }