1c87c5fbaSopenharmony_ci ####################################################### 2c87c5fbaSopenharmony_ci # Developer information for contributing to libcoap # 3c87c5fbaSopenharmony_ci ####################################################### 4c87c5fbaSopenharmony_ci 5c87c5fbaSopenharmony_ci1. The basics 6c87c5fbaSopenharmony_ci~~~~~~~~~~~~~ 7c87c5fbaSopenharmony_ciThe libcoap project is a FOSS project that is dual licensed. The maintainer 8c87c5fbaSopenharmony_cifor the libcoap is Olaf Bergmann <bergmann@tzi.org>. 9c87c5fbaSopenharmony_ciAny contributions have to be made under the terms of the 10c87c5fbaSopenharmony_cilicense 11c87c5fbaSopenharmony_ci 12c87c5fbaSopenharmony_ci * BSD 2-Clause (The BSD 2-Clause License) 13c87c5fbaSopenharmony_ci 14c87c5fbaSopenharmony_ciContributions made up to 2017-06-01 have been made under the dual 15c87c5fbaSopenharmony_cilicense model BSD 2-Clause and GPL v2+ (The GNU General Public License 16c87c5fbaSopenharmony_ci2.0 or later). 17c87c5fbaSopenharmony_ci 18c87c5fbaSopenharmony_ciThe used VCS for libcoap is Git, the main repository is living on GitHub. 19c87c5fbaSopenharmony_ciYou can clone (or fork directly on GitHub) on the repository site: 20c87c5fbaSopenharmony_ci 21c87c5fbaSopenharmony_ci https://github.com/obgm/libcoap 22c87c5fbaSopenharmony_ci 23c87c5fbaSopenharmony_ciPlease refer also to the libcoap website for additional information 24c87c5fbaSopenharmony_ci 25c87c5fbaSopenharmony_ci https://libcoap.net/ 26c87c5fbaSopenharmony_ci 27c87c5fbaSopenharmony_ciThe build environment is grounded on the classical autotools or CMake, the 28c87c5fbaSopenharmony_ciGNU GCC and the LLVM C-compiler (CLang) are supported. The Windows VS build 29c87c5fbaSopenharmony_cisystems are supported. 30c87c5fbaSopenharmony_ci 31c87c5fbaSopenharmony_ciDoxygen is used for creating a HTML based online documentation of the 32c87c5fbaSopenharmony_cilibcoap library. 33c87c5fbaSopenharmony_ci 34c87c5fbaSopenharmony_ci2. Communications 35c87c5fbaSopenharmony_ci~~~~~~~~~~~~~~~~~ 36c87c5fbaSopenharmony_ciThe main discussion and development platform for libcoap is the mailing list 37c87c5fbaSopenharmony_cion Sourceforge. 38c87c5fbaSopenharmony_ci 39c87c5fbaSopenharmony_ciNo matter if you just have a simple question, some specific problem or 40c87c5fbaSopenharmony_ciwant to discuss some patches, please write it to the mailing list. Please 41c87c5fbaSopenharmony_ciavoid personal mailings to the maintainer (or some other contributor) if 42c87c5fbaSopenharmony_ciyour questions will probably be in the interest of other users too. 43c87c5fbaSopenharmony_ciYou can subscribe to the list here: 44c87c5fbaSopenharmony_ci 45c87c5fbaSopenharmony_ci https://lists.sourceforge.net/lists/listinfo/libcoap-developers 46c87c5fbaSopenharmony_ci 47c87c5fbaSopenharmony_ciThe archive of the list can be found on: 48c87c5fbaSopenharmony_ci 49c87c5fbaSopenharmony_ci https://sourceforge.net/p/libcoap/mailman/libcoap-developers 50c87c5fbaSopenharmony_ci 51c87c5fbaSopenharmony_ciAlternatively, Issues can be raised at https://github.com/obgm/libcoap/issues 52c87c5fbaSopenharmony_ci 53c87c5fbaSopenharmony_ci3. Starting contributing 54c87c5fbaSopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~ 55c87c5fbaSopenharmony_ciAs written above, libcoap is maintained with the Git tools so you should be 56c87c5fbaSopenharmony_cifamiliar with the various git commands. 57c87c5fbaSopenharmony_ci 58c87c5fbaSopenharmony_ciThe libcoap project is using just two main branches, the 'main' branch is 59c87c5fbaSopenharmony_ciholding the point releases, all the development process is going on in the 60c87c5fbaSopenharmony_ci'develop' branch. 61c87c5fbaSopenharmony_ci 62c87c5fbaSopenharmony_ciTo start any contributing you first have to clone the git tree from the main 63c87c5fbaSopenharmony_cirepository on GitHub: 64c87c5fbaSopenharmony_ci 65c87c5fbaSopenharmony_ci git clone https://github.com/obgm/libcoap.git 66c87c5fbaSopenharmony_ci 67c87c5fbaSopenharmony_ci4. Working on the source 68c87c5fbaSopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~ 69c87c5fbaSopenharmony_ciAs one golden rule you should work on improvements within *your* own local 70c87c5fbaSopenharmony_cidevelopment branch! To do so you have to first checkout the 'develop' branch 71c87c5fbaSopenharmony_cias local branch and then start on top on this branch your own branch. So 72c87c5fbaSopenharmony_cicreate (or better say checkout) the local 'develop' branch: 73c87c5fbaSopenharmony_ci 74c87c5fbaSopenharmony_ci cd libcoap 75c87c5fbaSopenharmony_ci git checkout develop origin/develop 76c87c5fbaSopenharmony_ci 77c87c5fbaSopenharmony_ciNow you can simply start your own local branch (for example 'my-develop') 78c87c5fbaSopenharmony_ciwith the 'origin/develop' as parent so you can later create the patches 79c87c5fbaSopenharmony_ciagainst the the upstream development branch: 80c87c5fbaSopenharmony_ci 81c87c5fbaSopenharmony_ci git checkout -b my-develop 82c87c5fbaSopenharmony_ci 83c87c5fbaSopenharmony_ciAt this point you can now work with git, modify the source, commit 84c87c5fbaSopenharmony_cithe changes, amend if needed and test your work. 85c87c5fbaSopenharmony_ci 86c87c5fbaSopenharmony_ciAt some point you will have to generate patches to post them on the mailing 87c87c5fbaSopenharmony_cilist (and/or push your changes into your public Git tree). Multiple commits 88c87c5fbaSopenharmony_cifor your branch should be squash'ed into a single commit. This can be done 89c87c5fbaSopenharmony_cione of two ways. 90c87c5fbaSopenharmony_ci 91c87c5fbaSopenharmony_ciWay One: Push your changes to the github repository. 92c87c5fbaSopenharmony_ci 93c87c5fbaSopenharmony_ci git push origin my-develop 94c87c5fbaSopenharmony_ci 95c87c5fbaSopenharmony_ciThen go to https://github.com/obgm/libcoap/pulls and create your pull request 96c87c5fbaSopenharmony_cifor others to review. If changes are needed, then commit and squash changes 97c87c5fbaSopenharmony_ciand push the (forced) changes again. 98c87c5fbaSopenharmony_ci 99c87c5fbaSopenharmony_ci git push -f origin my-develop 100c87c5fbaSopenharmony_ci 101c87c5fbaSopenharmony_ciWay Two: Post your patch series on the mailing list so other contributors 102c87c5fbaSopenharmony_ciwill see your work and give further suggestions or discuss your work. 103c87c5fbaSopenharmony_ci 104c87c5fbaSopenharmony_ciTo be able to send a patch series you will now create the series itself as 105c87c5fbaSopenharmony_cisingle patches, this will be going easy with the 'git format-patch' command 106c87c5fbaSopenharmony_ciagainst the 'develop' branch, remember this is the upstream primary 107c87c5fbaSopenharmony_cidevelopment branch. 108c87c5fbaSopenharmony_ci 109c87c5fbaSopenharmony_ciTo not mix up your series with probably unrelated patches let git place the 110c87c5fbaSopenharmony_cipatches within a defined directory. Also, while create the patches, tell git to 111c87c5fbaSopenharmony_cicreate a cover letter patch so you can append some introducing words that will 112c87c5fbaSopenharmony_cihold probably explanations why you create the patches in the way you have done. 113c87c5fbaSopenharmony_ci 114c87c5fbaSopenharmony_ci git format-patch --cover-letter -o ../patches4libcoap 115c87c5fbaSopenharmony_ci 116c87c5fbaSopenharmony_ciThis command will create a patch series in ../patches4libcoap where you find a 117c87c5fbaSopenharmony_cipatch named '0000-cover-letter.patch'. Please modify this patch with some 118c87c5fbaSopenharmony_ciuseful information's for the mailing list. After finish this you now can send 119c87c5fbaSopenharmony_ciyour patches to libcoap-developers@lists.sourceforge.net 120c87c5fbaSopenharmony_ci 121c87c5fbaSopenharmony_ci git send-email ../patches4libcoap/* --to=libcoap-developers@lists.sourceforge.net 122c87c5fbaSopenharmony_ci 123c87c5fbaSopenharmony_ci5. Coding rules 124c87c5fbaSopenharmony_ci~~~~~~~~~~~~~~~ 125c87c5fbaSopenharmony_ciAs every FOSS project the libcoap project needs also some rules for coding. 126c87c5fbaSopenharmony_ciThere are lots but the main ones following are important! 127c87c5fbaSopenharmony_ci 128c87c5fbaSopenharmony_ci5.1 pre-commit 129c87c5fbaSopenharmony_ci-------------- 130c87c5fbaSopenharmony_cipre-commit is used to check the the syntax of *.c and *.h files according to 131c87c5fbaSopenharmony_cithe libcoap coding rules. The files are checked on github for every 'git push', 132c87c5fbaSopenharmony_ciand can be locally checked if pre-commit is installed for every 'git commit'. 133c87c5fbaSopenharmony_ci 134c87c5fbaSopenharmony_ci$ cd libcoap 135c87c5fbaSopenharmony_ci$ pip install pre-commit 136c87c5fbaSopenharmony_ci$ pre-commit install --allow-missing-config 137c87c5fbaSopenharmony_ci 138c87c5fbaSopenharmony_ci5.2 License and Copyright 139c87c5fbaSopenharmony_ci------------------------- 140c87c5fbaSopenharmony_ciEvery new file must contain a license and the copyright holder(s). Please 141c87c5fbaSopenharmony_citake a look into existing files and adopt the needed changes to your new 142c87c5fbaSopenharmony_cifile(s). 143c87c5fbaSopenharmony_ci 144c87c5fbaSopenharmony_ci5.3 Source Code Indentation 145c87c5fbaSopenharmony_ci--------------------------- 146c87c5fbaSopenharmony_ci* For better reading the indentation is set to 2 characters as spaces, this 147c87c5fbaSopenharmony_ci is depended on the often used nested functions like 'if-else'. Don't use 148c87c5fbaSopenharmony_ci TABs any where (apart from Makefile's indenting where TABs are mandatory)! 149c87c5fbaSopenharmony_ci Avoid trailing white spaces at the end of a line. 150c87c5fbaSopenharmony_ci It's appropriate to set up a modline like this one at first line within 151c87c5fbaSopenharmony_ci the source file: 152c87c5fbaSopenharmony_ci 153c87c5fbaSopenharmony_ci--8<---- 154c87c5fbaSopenharmony_ci/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 155c87c5fbaSopenharmony_ci--->8-- 156c87c5fbaSopenharmony_ci 157c87c5fbaSopenharmony_ci* For functions defined in *.h files, the function return type should be 158c87c5fbaSopenharmony_ci defined on the same line as the function name declaration. For functions 159c87c5fbaSopenharmony_ci defined in *.c files, the function return type should be defined on the 160c87c5fbaSopenharmony_ci previous line (for both declarations and implementations). 161c87c5fbaSopenharmony_ci 162c87c5fbaSopenharmony_ci* Single lines within the source code should not be longer then 78 163c87c5fbaSopenharmony_ci characters. 164c87c5fbaSopenharmony_ci 165c87c5fbaSopenharmony_ci* If there are functions with a lot of parameters that do not fit into the above 166c87c5fbaSopenharmony_ci rule split the declaration (in the *.h) and the implementation (in the *.c) 167c87c5fbaSopenharmony_ci into single lines per parameter. Each parameter should be aligned with the 168c87c5fbaSopenharmony_ci first defined parameter. For example like this (from src/coap_block.c): 169c87c5fbaSopenharmony_ci 170c87c5fbaSopenharmony_ci--8<---- 171c87c5fbaSopenharmony_ciint 172c87c5fbaSopenharmony_cicoap_add_block(coap_pdu_t *pdu, 173c87c5fbaSopenharmony_ci unsigned int len, 174c87c5fbaSopenharmony_ci const unsigned char *data, 175c87c5fbaSopenharmony_ci unsigned int block_num, 176c87c5fbaSopenharmony_ci unsigned char block_szx) { 177c87c5fbaSopenharmony_ci--->8-- 178c87c5fbaSopenharmony_ci 179c87c5fbaSopenharmony_ci5.4 Source Code Documentation 180c87c5fbaSopenharmony_ci----------------------------- 181c87c5fbaSopenharmony_ci* A useful source code documentation is mandatory. Mostly to be done within the 182c87c5fbaSopenharmony_ci source code files, but more complex description should be done in extra 183c87c5fbaSopenharmony_ci README files. 184c87c5fbaSopenharmony_ci 185c87c5fbaSopenharmony_ci* Please set up/adjust the doxygen documentation if you create new functions or 186c87c5fbaSopenharmony_ci change existing functions. The doxygen documentation has to be done in the 187c87c5fbaSopenharmony_ci header files as they are the public part of the libcoap and only use the 188c87c5fbaSopenharmony_ci @-syntax for doxygen commands (akin to javadoc). 189c87c5fbaSopenharmony_ci 190c87c5fbaSopenharmony_ci5.5 API Changes 191c87c5fbaSopenharmony_ci--------------- 192c87c5fbaSopenharmony_ci* Never break the API! 193c87c5fbaSopenharmony_ci Don't remove old functions and if there some changes are needed in some kind 194c87c5fbaSopenharmony_ci always provide a wrapper for the old call to let the library be backward 195c87c5fbaSopenharmony_ci compatible and mark the old function as @deprecated in the doxygen comment. 196c87c5fbaSopenharmony_ci Please discuss needed changes on the mailing list. 197c87c5fbaSopenharmony_ci 198c87c5fbaSopenharmony_ci5.6 Patches and Commits 199c87c5fbaSopenharmony_ci----------------------- 200c87c5fbaSopenharmony_ci* Git commits must be atomic and contain a declarative subject line (max 50 201c87c5fbaSopenharmony_ci characters if possible) and a body for a statement if needed. 202c87c5fbaSopenharmony_ci Use the opportunity to write a good explanation why your patch/commit is to 203c87c5fbaSopenharmony_ci handle the changes in the way you have done. Remember that other users can 204c87c5fbaSopenharmony_ci read your code but not necessary understand why the code is written this 205c87c5fbaSopenharmony_ci way. Don't use something to generic like "bugfix commit". 206c87c5fbaSopenharmony_ci 207c87c5fbaSopenharmony_ci* A patch/commit or a series of patches/commits have to ensure that the 208c87c5fbaSopenharmony_ci whole project is able to build up every thing, in short: Do not break 209c87c5fbaSopenharmony_ci any make target and test your work. 210c87c5fbaSopenharmony_ci 211c87c5fbaSopenharmony_ci* Every patch/commit should handle one single logical change. If more than 212c87c5fbaSopenharmony_ci one patch/commit is needed for a change explain it, respect the point 213c87c5fbaSopenharmony_ci above. If your subject line become much larger than 50 characters then 214c87c5fbaSopenharmony_ci typically your patch is to big for one single commit. 215c87c5fbaSopenharmony_ci 216c87c5fbaSopenharmony_ci* Commit message should begin with a submodule or unit the commit is for. 217c87c5fbaSopenharmony_ci Doing this in your commit message helps to find thematic other changes. If 218c87c5fbaSopenharmony_ci you have to search and find something with 'git log | grep [foo]' you will 219c87c5fbaSopenharmony_ci see why this is useful. Examples: 220c87c5fbaSopenharmony_ci 221c87c5fbaSopenharmony_ci rd.c: Fixed type-specifier warning 222c87c5fbaSopenharmony_ci Makefile.am: Added missing src/coap_address.c 223c87c5fbaSopenharmony_ci address.[hc]: make coap_address_equals() not inline on POSIX 224c87c5fbaSopenharmony_ci 225c87c5fbaSopenharmony_ci6. Where to start contributing? 226c87c5fbaSopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 227c87c5fbaSopenharmony_ciThere are various things you could starting on to contribute, the best 228c87c5fbaSopenharmony_ciis you simply pick up an issue you can easily see and just improve the 229c87c5fbaSopenharmony_cisituation. Please take also a look into the file TODO and choose a point 230c87c5fbaSopenharmony_cifrom there or point the maintainer to add other things here too. 231c87c5fbaSopenharmony_ci 232c87c5fbaSopenharmony_ci* Documentation 233c87c5fbaSopenharmony_ciWe always need better documentation on the source code, as well as improving 234c87c5fbaSopenharmony_cithe doxygen documentation in the header files. Updating the man pages for 235c87c5fbaSopenharmony_cimissing functions helps. 236c87c5fbaSopenharmony_ciAlso updated documentation on the usage of the libcoap and the example 237c87c5fbaSopenharmony_cibinaries is always useful. So we appreciate any help on this. 238c87c5fbaSopenharmony_ci 239c87c5fbaSopenharmony_ci* Manual Pages for example binaries 240c87c5fbaSopenharmony_ciManual pages are provided for the example binaries which have become more 241c87c5fbaSopenharmony_cicomplex over time with a variety of configuration options. It is possible 242c87c5fbaSopenharmony_cito work out how to use particular application functionality by reading the 243c87c5fbaSopenharmony_ciexamples source code. Improving documentation for usage would be useful. 244c87c5fbaSopenharmony_ci 245c87c5fbaSopenharmony_ci* Manual Pages for public API 246c87c5fbaSopenharmony_ciAs well as the doxygen documentation, manual pages are being written for the 247c87c5fbaSopenharmony_cipublic licoap API where functions are defined, what the parameters mean as 248c87c5fbaSopenharmony_ciwell as providing simple coding examples. These manual pages are also 249c87c5fbaSopenharmony_ciembedded in the doxygen output, the latest copy of which can be seen at 250c87c5fbaSopenharmony_cihttps://libcoap.net/doc/reference/develop/ 251c87c5fbaSopenharmony_ciUpdating these manual pages for the missing functions, correcting errors 252c87c5fbaSopenharmony_cior providing simple examples of function usage would be helpful. 253c87c5fbaSopenharmony_ci 254c87c5fbaSopenharmony_ci* HowTo's 255c87c5fbaSopenharmony_ciThe libcoap library has now a lot of functions you can use. 256c87c5fbaSopenharmony_ciUnfortunately there is no good user guide on how to use the libcoap in 257c87c5fbaSopenharmony_ciany external project. This means there is no HowTo or CheatSheet for a 258c87c5fbaSopenharmony_ciprogramming person available. Do you want to write up something? 259c87c5fbaSopenharmony_ci 260c87c5fbaSopenharmony_ci* Missing functionality 261c87c5fbaSopenharmony_ciThere are some features that are still missing inside the libcoap. For 262c87c5fbaSopenharmony_ciexample some DTLS implementations and proxy functionality. 263c87c5fbaSopenharmony_ci 264