{"id":13423521,"url":"https://github.com/davidmoreno/onion","last_synced_at":"2025-05-15T10:07:30.441Z","repository":{"id":1099925,"uuid":"961335","full_name":"davidmoreno/onion","owner":"davidmoreno","description":"C library to create simple HTTP servers and Web Applications.","archived":false,"fork":false,"pushed_at":"2022-10-17T18:56:32.000Z","size":3665,"stargazers_count":2046,"open_issues_count":62,"forks_count":254,"subscribers_count":100,"default_branch":"master","last_synced_at":"2025-04-14T16:57:45.515Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.coralbits.com/libonion/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidmoreno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-10-04T18:19:26.000Z","updated_at":"2025-04-10T10:52:38.000Z","dependencies_parsed_at":"2022-07-15T07:16:59.068Z","dependency_job_id":null,"html_url":"https://github.com/davidmoreno/onion","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmoreno%2Fonion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmoreno%2Fonion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmoreno%2Fonion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmoreno%2Fonion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidmoreno","download_url":"https://codeload.github.com/davidmoreno/onion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051073,"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":[],"created_at":"2024-07-31T00:00:36.583Z","updated_at":"2025-05-15T10:07:25.428Z","avatar_url":"https://github.com/davidmoreno.png","language":"C","readme":"# Onion http server library\n\n![Travis status](https://travis-ci.org/davidmoreno/onion.svg?branch=master#svg)[Travis status](https://travis-ci.org/davidmoreno/onion)\n\n![Coverity status](https://scan.coverity.com/projects/1815/badge.svg#svg)[Coverity status](https://scan.coverity.com/projects/1815)\n\n\nOnion is a C library to create simple HTTP servers and Web Applications.\n\n`master` the development branch. Current stable branch is `onion-0-8`.\n\n## Introduction\n\nThe use case is an existing application, or a new one, that needs some HTTP interconnection\nwith the world. It uses the library to add some handlers for specific URLs and generate and\nserve the dynamic data as needed.\n\nIt also has security goals (SSL support) so that you just concentrate on what you want\nto serve, and serve it.\n\nIts not a web server per se, as it is not an executable.\n\nIf you want to compare to a web server, a web server would use a module or plugin to add\nsome functionality. With libonion you have the functionality and add the webserver as a plugin.\n\nThere is a wiki available at https://github.com/davidmoreno/onion/wiki, with useful\ninformation on how to get started using Onion and it's internal workings.\n\nAPI documentation is at http://coralbits.com/static/onion/.\n\nThere is a mailing list at https://groups.google.com/a/coralbits.com/forum/?fromgroups=#!forum/onion-dev\n\n## Collaborate!\n\nYou can, and are encouraged, to branch at github, download and tweak onion to use it in your\nprojects.\n\nThe library is dual licensed under the Apache2 license and GPLv2+, so you can make almost anything\nwith it, use it in your commercial and free software programs, and modify it to your needs.\n\nPlease join the mailing list at https://groups.google.com/a/coralbits.com/group/onion-dev/topics,\nto ask your questions and comment on your success using onion.\n\nThere is also a blog to keep everybody informed about news on onion at http://blog.coralbits.com/.\n\n## Download\n\nThere are third party packages available:\n\n * RPM based: http://software.opensuse.org/download.html?project=home%3Admoreno\u0026package=onion\n * Raspberry pi: http://packages.aisoy.com/debian/pool/unstable/libo/libonion/\n * Arch Linux: https://aur.archlinux.org/packages/libonion-git/\n\nIf you know of any other packaged version, please send me a note.\n\nAs always they may be outdated, if you want the latest and greatest, do a manual compile and install.\n\nThanks to Ruediger Meier for helping for so long with the RPM packages.\n\n## Compile and Install\n\nManual compile and install:\n\n```bash\n$ git clone git@github.com:davidmoreno/onion.git\n$ cd onion\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make\n$ sudo make install\n```\n\nTo compile with debugging enabled, use\n\n```bash\n$ cmake -DCMAKE_BUILD_TYPE=Debug ..\n```\n\nTo run with some debug messages, set the ONION_DEBUG and/or\nONION_DEBUG0 environment variable containing some source file names,\ne.g.\n\n```bash\n$ export ONION_DEBUG0='request.c url.c'\n```\n\n## Dependencies\n\nRequired:\n\n* C compiler\n* cmake\n* make\n* One of:\n  - epoll (Linux)\n  - [libevent](http://libevent.org/) (Multiarch)\n  - [libev](https://github.com/enki/libev) (Multiarch)\n\n\nThis compilers and minimum versions are known to work:\n\n* Linux:\n  * GCC 4.4\n  * clang 3.0\n\nFor the C++ bindings a C++11 compiler is needed:\n\n* Linux:\n  * GCC 4.8\n  * clang 3.7\n\nOptional; Onion will compile but some functionality will not be available:\n\n* gnutls and gcrypt (SSL support)\n* pthreads (threading support)\n* libxml2 (WebDAV support)\n* libpam (HTTP Basic Auth support using PAM)\n* C++ compiler\n* Systemd (support for listening on systemd sockets)\n* sqlite3 (sqlite3 session backend)\n* hiredis (Redis session backend)\n\nOptional for examples:\n\n* cairo\n* libpng2\n* boehm gc\n* libjpeg\n\n## Semantic versioning.\n\nStarting with Onion 0.8.0, we use semantic versioning, making the following\npromises:\n\n* Version format is [MAJOR].[MINOR].[PATCH].\n* Only make API and ABI changes at major versions. Can add functionalities at\n  minor releases.\n* Only remove API functions at major versions. No changes in semantics never.\n* Minor versions are always ABI back-compatible. This means that if you compiled\n  with a previous minor version and same major version, it will still compile\n  and work.\n* Only add API functions at minor versions.\n* Only fix patches a patch revisions.\n\nPatch revisions are is a non sequential number, so after 0.8.0 is not 0.8.1, but\nmaybe 0.8.23. It will always increase.\n\nCheck `onion/version.h` for more information on version control.\n\n## SSL Support\n\nIf at compile time the build script finds the gnutls libraries, SSL support will be compiled in. It can be\ndeactivated anyway at ./CMakeLists.txt.\n\nTo use it you have to set the certificates, and you can check if its on, checking the flag\nO_SSL_ACTIVATED.\n\nIf support is not compiled in, then the library will not use SSL, but for the user of the library the\ninterface is the same; it will only change that when trying to set the certificates it\nwill fail. Anwyay for clients its just to use the interface and they dont care at all\nif suport is in or not. No more than being able to use SSL.\n\nThis is not mandatory because there may be moments when the program's users do not\nwant to support SSL for whatever reasons, for example speed.\n\n\n## Threads support\n\nCurrently there are two threading modes. It can be set so the server is created as\nthreaded (O_THREADED), and it will create a new thread per connection. There is no\ndata protection as on the listen phase there should not be any change to onion structures.\n\nNevertheless if new handlers are created they must set their own threading support\nas neccesary.\n\nIt can be deactivated at CMakeLists.txt. If no pthreads lib is found on the system, it\nis not compiled in.\n\nAlso when thread support is on, onion server can be set to work on another (non-main) thread.\nThis is independant from O_THREADED operation; it can have one thread with your normal\napplication and another thread that listens and processes web-requests. Its set with the\nO_DETACH_LISTEN flag. This is very useful when adding an extra web server to your application\nso it can be added without changes to the flow of your application, but you will need to\nthread protect your data if you access to it from the web server.\n\nFinally there is a pool mode. Users can set a default number of threads (onion_set_max_threads),\nand using epoll the data is given to the threads. This is the highest performant method, with\nup to 30k web-requests served on a Intel(R) Core(TM)2 Duo CPU T6500  @2.10GHz.\n\n\n## Customizing low-level allocation and threads\n\nSometimes it may be needed to customize memory allocation and/or\nthreads operation.  This could be useful when using an alternative\nmalloc, or if you wanted to use Hans Boehm's conservative garbage\ncollector from http://www.hboehm.info/gc/ e.g. if you use GNU\nguile. Then you need to define your own memory routines and pass them\nto `onion_low_initialize_memory_allocation` before any other calls to\nonion. Likewise, to customize threads operations, call\n`onion_low_initialize_threads`.  See comments in header file `low.h`. A\nprogram using Onion and Boehm's GC should first define a memory\nfailure routine which should never return:\n\n```C\n/* the memory failure routine should never return! */\nstatic void memory_failure(const char*msg) {\n  perror(msg);\n  exit(EXIT_FAILURE);\n};\n```\n\nThen, your program (using both onion and Boehm's GC) should initialize\nboth memory routines and threads, like:\n\n```C\nonion_low_initialize_memory_allocation\n  (GC_malloc,  GC_malloc_atomic,  GC_calloc,\n   GC_realloc, GC_strdup, GC_free,\n   memory_failure);\n\nonion_low_initialize_threads\n  (GC_pthread_create, GC_pthread_join,\n   GC_pthread_cancel, GC_pthread_detach,\n   GC_pthread_exit, GC_pthread_sigmask);\n```\n\nYou might need to define your `GC_calloc` using `GC_malloc` and\n`memset` if your version of Boehm's GC don't provide it. After these\nlow-level initialization you can use Onion as usual.\n\nYou could also want to call just `onion_low_initialize_threads` if you\nwanted to name threads created by the onion library (using\n`pthread_setname_np` on Linux) and/or change their priority (using\n`pthread_setschedprio`), etc.\n\n\n## ARM Support\n\nIt can be cross compiled for ARM directly from cmake. Just do:\n\n```bash\n$ mkdir arm\n$ cd arm\n$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain/arm.txt\n$ make\n```\n\nIt needs the current system opack and otemplate to compile some examples, so if you want to use\nthe examples on your instalation, compile and install libonion for the current system first.\n\nTested on ubuntu 10.10, with gcc-4.5-arm-linux-gnueabi and g++-4.5-arm-linux-gnueabi installed.\n\n\n## Templating support\n\nStarting on 0.3.0 development onion has templating support via otemplate. It is a template\nsystem similar to django templates (http://docs.djangoproject.com/en/dev/topics/templates/).\n\nCheck more information on how to use them at tools/otemplate/README.rst.\n\n## I18N\n\nThere is I18N support. Check wiki for details or fileserver_otemplate example.\n\n## Systemd\n\nSystemd is integrated. If want to use it, just pass the flag O_SYSTEMD to the onion_new().\n\nOterm has example socket and service files for oterm support.\n\n## FreeBSD/Darwin\n\nSince september 2013 there is support for FreeBSD using libev or libevent. This work is not as tested\nas the Linux version, but if some compilation error arises, please send the bug report and we will fix\nit ASAP.\n\nOSX/Darwin support is also available on the darwin branch.\n\nOnce this work stabilizes it will be merged back to master.\n\n## Environment variables\n\nYou can set the following environment variables -e.g. with the export builtin of bash- to modify runtime behaviour of onion:\n\n* ONION_LOG\n\n  - noinfo   -- Disables all info output to the console, to achieve faster results\n  - nocolor  -- Disable color use by the log\n  - nodebug  -- Do not show debug lines\n  - syslog   -- Log to syslog. Can be changed programatically too, with the onion_log global function.\n\n* ONION_DEBUG0   -- Set the filename of a c source file, and DEBUG0 log messages are written. This is normally very verbose.\n* ONION_SENDFILE -- Set to 0 do disable sendfile. Under some file systems it does not work. Until a detection code is in place, it can be disabled with this.\n\n## Binary compatibility breaks\n\nWe try hard to keep binary compatibility, but sometimes its hard. Here is a list of ABI breaks:\n\n### 0.4.0\n\n* Onion object private flags have moved. If on your code you rely on them, must recompile. If\n  dont rely on them, everything should keep working.\n","funding_links":[],"categories":["C","Networking","内存分配","网络","Service Toolkits"],"sub_categories":["网络","C"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidmoreno%2Fonion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidmoreno%2Fonion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidmoreno%2Fonion/lists"}