{"id":19529224,"url":"https://github.com/softmotions/iwnet","last_synced_at":"2025-04-05T00:08:05.021Z","repository":{"id":38747442,"uuid":"395197662","full_name":"Softmotions/iwnet","owner":"Softmotions","description":"Pure C Asynchronous HTTP/IO framework with routing, websockets, SSL and reverse proxy.","archived":false,"fork":false,"pushed_at":"2025-03-02T05:47:52.000Z","size":2208,"stargazers_count":175,"open_issues_count":4,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-28T23:06:52.600Z","etag":null,"topics":["c","c-library","c-programming","cpp","http","http-proxy","http-server","http-server-library","https","ingress","proxy","reverse-proxy","server","ssl","web","web-framewok","web-framework","websocket","websocket-server","websockets"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Softmotions.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-12T04:49:21.000Z","updated_at":"2025-03-02T05:47:55.000Z","dependencies_parsed_at":"2023-02-12T15:31:22.680Z","dependency_job_id":"2ba3289d-fe73-4a45-a81f-ed510cc8564c","html_url":"https://github.com/Softmotions/iwnet","commit_stats":{"total_commits":521,"total_committers":2,"mean_commits":260.5,"dds":"0.0038387715930902067","last_synced_commit":"a10a7834e30b2a3bc1aaa0ac2c6276c2a8ae68ad"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Softmotions%2Fiwnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Softmotions%2Fiwnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Softmotions%2Fiwnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Softmotions%2Fiwnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Softmotions","download_url":"https://codeload.github.com/Softmotions/iwnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266564,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-library","c-programming","cpp","http","http-proxy","http-server","http-server-library","https","ingress","proxy","reverse-proxy","server","ssl","web","web-framewok","web-framework","websocket","websocket-server","websockets"],"created_at":"2024-11-11T01:22:55.126Z","updated_at":"2025-04-05T00:08:05.000Z","avatar_url":"https://github.com/Softmotions.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IWNET\n\n**NOTE: Issues tracker is disabled. You are welcome to contribute, pull requests accepted.**\n\nPure `C` asynchronous HTTP framework providing websockets client/server, SSL, reverse proxy and routing.\n\nWorks on Linux, macOS, FreeBSD\n\n* [Fast asynchronous HTTP server](./src/http) ([iwn_http_server.h](./src/http/iwn_http_server.h))\n* [Web framework based on HTTP server](./src/http) ([iwn_wf.h](./src/http/iwn_wf.h))   \n* Ultra fast HTTP Reverse Proxy ([iwn_http_server.h](./src/http/iwn_http_server.h))\n* Websocket client and server ([iwn_ws_server.h](./src/ws/iwn_ws_server.h), [iwn_ws_client.h](./src/ws/iwn_ws_client.h))\n* Poller reactor ([iwn_poller.h](./src/poller/iwn_poller.h))\n* SSL Layer is based on BearSSL ([iwn_brssl_poller_adapter.h](./src/ssl/iwn_brssl_poller_adapter.h))\n* Manager of child processes ([iwn_proc.h](./src/poller/iwn_proc.h))\n* Timer ([iwn_scheduler.h](./src/poller/iwn_scheduler.h))\n* Inotify watcher wrapper [iwn_watcher](./src/poller/iwn_watcher.h)\n\n## Build from sources\n\n**Prerequisites**\n\n* Linux, macOS or FreeBSD\n* CMake 3.12 or greater\n* gcc or clang compiler \n* GNU Make or Ninja \n\n**Building**\n\n```sh\ngit clone https://github.com/Softmotions/iwnet.git\n\nmkdir -p ./iwnet/build \u0026\u0026 cd ./iwnet/build\n\ncmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_EXAMPLES=ON\n\nmake \n```\n\n## IWSTART\n\nIWSTART is an automatic CMake initial project generator for C projects based on [iowow](https://github.com/Softmotions/iowow) / [iwnet](https://github.com/Softmotions/iwnet) / [ejdb2](https://github.com/Softmotions/ejdb) libs.\n\nhttps://github.com/Softmotions/iwstart\n\n# Used by\n\n* [EJDB2 Embeddable JSON Database engine](https://github.com/Softmotions/ejdb)\n* [Wirow Video Conferencing Platform](https://github.com/wirow-io/wirow-server)\n\n\n\n\n## Asynchronous HTTP Framework\n\n### Examples\n#### Simple echo server\n\n```sh\n  ./echo_http_server --ssl\n \n  curl -k -XPUT -d'Hello' https://localhost:8080/echo\n  Hello\n  I'm an echo web server\n```\n\necho_http_server.c\n\n```c\n#include \"iwn_wf.h\"\n\n#include \u003ciowow/iwconv.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003csignal.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cerrno.h\u003e\n\nstatic struct iwn_poller *poller;\nstatic struct iwn_wf_ctx *ctx;\n\nstatic void _on_signal(int signo) {\n  fprintf(stderr, \"\\nExiting...\\n\");\n  iwn_poller_shutdown_request(poller);\n}\n\nstatic int _handle_echo(struct iwn_wf_req *req, void *user_data) {\n  fprintf(stderr, \"Echo handler called\\n\");\n  iwn_http_response_printf(req-\u003ehttp, 200, \"text/plain\", \"%.*s\\n%s\\n\",\n                           (int) req-\u003ebody_len, req-\u003ebody, (char*) user_data);\n  return IWN_WF_RES_PROCESSED;\n}\n\nint main(int argc, char *argv[]) {\n  signal(SIGPIPE, SIG_IGN);\n  if (  signal(SIGTERM, _on_signal) == SIG_ERR\n     || signal(SIGINT, _on_signal) == SIG_ERR) {\n    return EXIT_FAILURE;\n  }\n\n  iwrc rc = 0;\n  bool ssl = false;\n  int port = 8080;\n\n  for (int i = 1; i \u003c argc; ++i) {\n    if (strcmp(argv[i], \"--ssl\") == 0) {\n      ssl = true;\n    } else if (strcmp(argv[i], \"--port\") == 0 \u0026\u0026 i + 1 \u003c argc) {\n      port = iwatoi(argv[i + 1]);\n    }\n  }\n  RCC(rc, finish, iw_init());              // Init iowow runtime, logging, etc..\n  RCC(rc, finish, iwn_wf_create(0, \u0026ctx)); // Create web server context\n  RCC(rc, finish, iwn_wf_route(\u0026(struct iwn_wf_route) {\n    .ctx = ctx,\n    .pattern = \"/echo\",\n    .handler = _handle_echo,\n    .user_data = \"I'm an echo web server\",\n    .flags = IWN_WF_PUT | IWN_WF_POST\n  }, 0));\n\n  RCC(rc, finish, iwn_poller_create(0, 0, \u0026poller));\n\n  struct iwn_wf_server_spec spec = {\n    .listen = \"localhost\",\n    .port   = port,\n    .poller = poller,\n  };\n  if (ssl) {\n    spec.ssl.private_key = \"./server-eckey.pem\";\n    spec.ssl.private_key_len = -1;\n    spec.ssl.certs = \"./server-ecdsacert.pem\";\n    spec.ssl.certs_len = -1;\n  }\n\n  // Print out a routes configuration.\n  iwn_wf_route_print(ctx-\u003eroot, stderr);\n  // Configure HTTP server.\n  RCC(rc, finish, iwn_wf_server(\u0026spec, ctx));\n  fprintf(stderr,\n          \"\\nOpen terminal and run:\\n\\tcurl -k -XPUT -d'Hello' %s://%s:%d\\n\",\n          (ssl ? \"https\" : \"http\"),\n          spec.listen,\n          spec.port);\n\n  // Start fds poller reactor.\n  iwn_poller_poll(poller);\n\nfinish:\n  iwn_poller_destroy(\u0026poller);\n  if (rc) {\n    iwlog_ecode_error3(rc);\n    return EXIT_FAILURE;\n  } else {\n    return EXIT_SUCCESS;\n  }\n}\n```\n\n#### Todo list REST API server\n\n[todolist_http_server.c](https://github.com/Softmotions/iwnet/tree/master/src/http/examples/todolist_http_server.c)\n\n```sh\n./todolist_http_server --ssl\n0001 [root:*] \n0002   [/todo\u003e ALL\n0003     {create:/([a-zA-z]+[a-z0-9A-Z]*)] PUT\n0004     {get:/([0-9]+)] GET\n0005     {remove:/([0-9]+)] DELETE\n0006     [list:*] GET\n0007     [done:*] POST\n\n Create a new 'Hello' todo entry:\n\tcurl -k -XPUT -d'Say Hello' https://localhost:8080/todo/Hello\n\tcurl -k -XPUT -d'Say Hello' https://localhost:8080/todo/Hello?done=1\n\n List all todo list items:\n\tcurl -k https://localhost:8080/todo\n\n Get task #1 details:\n\tcurl -k https://localhost:8080/todo/1\n\n Remove task #2 from todo list:\n\tcurl -k -XDELETE https://localhost:8080/todo/2\n\n Update done status of task #2:\n\tcurl -k -XPOST -d'id=2\u0026done=1' https://localhost:8080/todo\n```\n\n#### More examples \n\n[Real life large project - Wirow video-conferencing server](https://github.com/wirow-io/wirow-server)\n\nYou may find many helpful code examples by looking into \n[framework test code](https://github.com/Softmotions/iwnet/tree/master/src/http/tests)\n\n* [server2.c](https://github.com/Softmotions/iwnet/tree/master/src/http/tests/server2.c)\n* [server1.c](https://github.com/Softmotions/iwnet/tree/master/src/http/tests/server1.c)\n* [HTTP Proxy: proxy1.c](https://github.com/Softmotions/iwnet/tree/master/src/http/tests/proxy1.c)\n\n# License\n\n```\n\nMIT License\n\nCopyright (c) 2012-2024 Softmotions Ltd \u003cinfo@softmotions.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftmotions%2Fiwnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftmotions%2Fiwnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftmotions%2Fiwnet/lists"}