├── .default-version ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .travis ├── after_success.sh ├── before_install.sh ├── before_script.sh ├── deploy.prv.enc ├── deploy.pub └── script.sh ├── .uncrustify.cfg ├── CHANGELOG ├── CONTRIBUTING.md ├── HACKING.md ├── LICENSE ├── Makefile.am ├── NEWS.md ├── README.md ├── Xcode ├── macOS │ ├── config.h │ └── nyoci-config.h └── nyoci.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ └── WorkspaceSettings.xcsettings ├── bootstrap.sh ├── configure.ac ├── contiki-src ├── Makefile.nyoci ├── examples │ ├── nyoci-complex │ │ ├── .gitignore │ │ ├── Makefile │ │ └── nyoci-complex.c │ ├── nyoci-plugtest │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── nyoci-plugtest.avr-raven.gdb │ │ └── nyoci-plugtest.c │ └── nyoci-simple │ │ ├── .gitignore │ │ ├── Makefile │ │ └── nyoci-simple.c ├── led-node.c ├── led-node.h ├── nyoci-contiki-config.h ├── nyoci-task.c ├── nyoci-task.h ├── sensor-node.c └── sensor-node.h ├── doc ├── Makefile.am ├── nyocictl.1 └── oss-plan.md ├── doxygen.cfg.in ├── etc ├── Dockerfile ├── build-in-docker.sh ├── libnyoci.rb ├── run-in-docker.sh └── smcp-to-libnyoci.sed └── src ├── .gitignore ├── Makefile.am ├── examples ├── .gitignore ├── Makefile.am ├── example-1.c ├── example-2.c ├── example-3.c ├── example-4.c └── example-multicast-request.c ├── libnyoci ├── Makefile.am ├── assert-macros.h ├── btree.c ├── btree.h ├── coap.c ├── coap.h ├── fasthash.c ├── fasthash.h ├── libnyoci.h ├── libnyoci.pc.in ├── ll.h ├── nyoci-async.c ├── nyoci-async.h ├── nyoci-config.h.in ├── nyoci-defaults.h ├── nyoci-dupe.c ├── nyoci-dupe.h ├── nyoci-helpers.h ├── nyoci-inbound.c ├── nyoci-internal.h ├── nyoci-logging.h ├── nyoci-missing.c ├── nyoci-missing.h ├── nyoci-observable.c ├── nyoci-observable.h ├── nyoci-opts.h ├── nyoci-outbound.c ├── nyoci-plat-net-func.h ├── nyoci-plat-tls-func.h ├── nyoci-session.c ├── nyoci-session.h ├── nyoci-status.h ├── nyoci-timer.c ├── nyoci-timer.h ├── nyoci-transaction.c ├── nyoci-transaction.h ├── nyoci.c ├── string-utils.c ├── string-utils.h ├── url-helpers.c └── url-helpers.h ├── libnyociextra ├── Makefile.am ├── libnyociextra.h ├── libnyociextra.pc.in ├── nyoci-list.c ├── nyoci-node-router.c ├── nyoci-node-router.h ├── nyoci-var-handler.c └── nyoci-var-handler.h ├── missing ├── Makefile.am ├── fgetln.h ├── getline.c ├── strlcat │ ├── Makefile.am │ ├── strlcat.c │ ├── strlcat.h │ └── strlcat_test.c └── strlcpy │ ├── Makefile.am │ ├── strlcpy.c │ ├── strlcpy.h │ └── strlcpy_test.c ├── nyocictl ├── Makefile.am ├── cmd_delete.c ├── cmd_delete.h ├── cmd_get.c ├── cmd_get.h ├── cmd_list.c ├── cmd_list.h ├── cmd_post.c ├── cmd_post.h ├── cmd_repeat.c ├── cmd_repeat.h ├── help.c ├── help.h ├── main.c └── nyocictl.h ├── plat-net ├── posix │ ├── Makefile.am │ ├── nyoci-plat-net-internal.h │ ├── nyoci-plat-net.c │ └── nyoci-plat-net.h └── uip │ ├── Makefile.am │ ├── nyoci-plat-net-internal.h │ ├── nyoci-plat-net.c │ └── nyoci-plat-net.h ├── plat-tls └── openssl │ ├── Makefile.am │ ├── nyoci-plat-tls.c │ └── nyoci-plat-tls.h ├── plugtest ├── Makefile.am ├── README.md ├── main-client.c ├── main-server.c ├── plugtest-server.c ├── plugtest-server.h └── selftest.sh ├── tests ├── Makefile.am └── test-concurrency.c ├── version.c.in └── version.h /.default-version: -------------------------------------------------------------------------------- 1 | 0.07.00rc1 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.[ch] text whitespace=trailing-space,space-before-tab,indent-with-non-tab,-tab-in-indent,tabwidth=4 3 | *.rb text whitespace=trailing-space,space-before-tab,-indent-with-non-tab,tab-in-indent,tabwidth=2 4 | *.yml text whitespace=trailing-space,space-before-tab,-indent-with-non-tab,tab-in-indent,tabwidth=4 5 | *.md text whitespace=-trailing-space,space-before-tab,-indent-with-non-tab,-tab-in-indent 6 | Makefile.* text whitespace=trailing-space,space-before-tab,indent-with-non-tab,-tab-in-indent,tabwidth=4 7 | Makefile text whitespace=trailing-space,space-before-tab,indent-with-non-tab,-tab-in-indent,tabwidth=4 8 | *.bat text eol=crlf 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *.o 4 | *.lo 5 | .deps 6 | *.orig 7 | Makefile.in 8 | *~ 9 | *.xcuserdatad 10 | xcuserdata 11 | *.a 12 | *.la 13 | *.gz 14 | *.log 15 | *.trs 16 | *.dylib 17 | *.lai 18 | .libs 19 | *.gcno 20 | *.gcda 21 | doxygen.cfg 22 | /doc/html 23 | /doc/latex 24 | /build 25 | /DerivedData 26 | /autom4te.cache 27 | /aclocal.m4 28 | /config.h.in 29 | /config.log 30 | /config.status 31 | /configure 32 | /libtool 33 | /Makefile 34 | /doc/Makefile 35 | /src/config.h 36 | /src/nyocictl/nyocictl 37 | /src/libnyoci/libnyoci.pc 38 | /src/libnyoci/nyoci-config.h 39 | /src/libnyoci/stamp-h2 40 | /src/libnyociextra/libnyociextra.pc 41 | /m4 42 | /src/stamp-h1 43 | /src/config.h.in 44 | /src/plugtest/nyoci-plugtest-client 45 | /src/plugtest/nyoci-plugtest-server 46 | /src/libnyoci/btreetest 47 | /src/tests/test-concurrency 48 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | addons: 4 | apt: 5 | packages: 6 | - git 7 | - bsdtar 8 | - libtool 9 | - automake 10 | - autoconf 11 | - autoconf-archive 12 | - libreadline-dev 13 | - libssl-dev 14 | 15 | os: 16 | - linux 17 | # - osx 18 | 19 | compiler: 20 | - clang 21 | - gcc 22 | 23 | before_install: 24 | - .travis/before_install.sh 25 | 26 | before_script: 27 | - .travis/before_script.sh 28 | 29 | script: 30 | - .travis/script.sh 31 | 32 | after_success: 33 | - ssh-agent .travis/after_success.sh 34 | 35 | env: 36 | - BUILD_MAKEARGS='distcheck' BUILD_PLATFORM='unix' BUILD_MAKEPATH='build' 37 | - BUILD_MAKEARGS='check' BUILD_CONFIGFLAGS='--enable-embedded NYOCI_CONF_TRANS_ENABLE_BLOCK2=1 NYOCI_CONF_TRANS_ENABLE_OBSERVING=1' BUILD_PLATFORM='unix' BUILD_MAKEPATH='build' 38 | - BUILD_MAKEARGS='check' BUILD_CONFIGFLAGS='--enable-tls' BUILD_PLATFORM='unix' BUILD_MAKEPATH='build' 39 | 40 | matrix: 41 | exclude: 42 | - os: osx 43 | compiler: gcc 44 | - os: osx 45 | env: BUILD_MAKEARGS='check' BUILD_CONFIGFLAGS='--enable-tls' BUILD_PLATFORM='unix' BUILD_MAKEPATH='build' 46 | include: 47 | - os: linux 48 | compiler: gcc 49 | env: BUILD_PLATFORM='contiki' BUILD_MAKEPATH='contiki-src/examples/nyoci-plugtest' BUILD_MAKEARGS='TARGET=minimal-net CONTIKI=../../../contiki' SUPPORTED_CONTIKI_REF='1d69099' 50 | - os: linux 51 | compiler: gcc 52 | env: BUILD_PLATFORM='contiki' BUILD_MAKEPATH='contiki-src/examples/nyoci-complex' BUILD_MAKEARGS='TARGET=native CONTIKI=../../../contiki' SUPPORTED_CONTIKI_REF='1d69099' 53 | - os: linux 54 | compiler: gcc 55 | env: BUILD_PLATFORM='contiki' BUILD_MAKEPATH='contiki-src/examples/nyoci-simple' BUILD_MAKEARGS='TARGET=minimal-net CONTIKI=../../../contiki' SUPPORTED_CONTIKI_REF='1d69099' 56 | -------------------------------------------------------------------------------- /.travis/after_success.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PREV_PATH="`pwd`" 4 | 5 | die() { 6 | echo " *** ERROR: " $* 7 | exit 1 8 | } 9 | 10 | set -x 11 | 12 | prep_ssh_key() { 13 | openssl aes-256-cbc -K "${encrypted_0f1462f1026b_key}" -iv "${encrypted_0f1462f1026b_iv}" -in .travis/deploy.prv.enc -out .travis/deploy.prv -d && 14 | chmod 600 .travis/deploy.prv && 15 | ssh-add .travis/deploy.prv 16 | } 17 | 18 | AUTOCONF_BRANCH="autoconf/$TRAVIS_BRANCH" 19 | 20 | if [ $TRAVIS_REPO_SLUG = "darconeous/libnyoci" ] \ 21 | && [ $TRAVIS_BRANCH = "master" ] \ 22 | && [ $TRAVIS_OS_NAME = "linux" ] \ 23 | && [ $TRAVIS_PULL_REQUEST = "false" ] \ 24 | && [ $BUILD_MAKEPATH = "build" ] \ 25 | && [ $BUILD_MAKEARGS = "distcheck" ] \ 26 | && true 27 | then 28 | git config --global user.name "Travis CI" || die 29 | git config --global user.email "noreply@travis-ci.com" || die 30 | 31 | # This will fail if this isn't a shallow checkout, so we ignore the return value. 32 | git fetch --unshallow origin 33 | 34 | git fetch origin scripts:scripts ${AUTOCONF_BRANCH}:${AUTOCONF_BRANCH} ${TRAVIS_BRANCH}:${TRAVIS_BRANCH} || die 35 | 36 | PREVREV="`git rev-parse ${AUTOCONF_BRANCH}`" 37 | 38 | echo "Checking for update to '${AUTOCONF_BRANCH}'..." 39 | 40 | git checkout scripts || die 41 | 42 | ./git-update-bootstrap-tags --no-push --no-pull --no-make-branches ${TRAVIS_BRANCH} || die 43 | 44 | CHANGED_LINES=`git diff "${PREVREV}".."__AUTOCONF_HEAD" | grep '^[-+]' | grep -v '^[-+]SOURCE_VERSION=' | wc -l || echo 3` 45 | 46 | if [ "$CHANGED_LINES" -gt "2" ] 47 | then 48 | echo "Branch '${AUTOCONF_BRANCH}' is OUT OF DATE." 49 | 50 | git checkout "${TRAVIS_BRANCH}" || die 51 | 52 | prep_ssh_key || die "prep_ssh_key failed" 53 | 54 | git push "git@github.com:${TRAVIS_REPO_SLUG}.git" "__AUTOCONF_HEAD:${AUTOCONF_BRANCH}" || die "Unable to push" 55 | else 56 | echo "Branch '${AUTOCONF_BRANCH}' is still up-to-date." 57 | fi 58 | else 59 | echo "Skipping update of '${AUTOCONF_BRANCH}'." 60 | fi 61 | 62 | exit 0 63 | -------------------------------------------------------------------------------- /.travis/before_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | die() { 3 | echo " *** ERROR: " $* 4 | exit 1 5 | } 6 | 7 | set -x 8 | 9 | # This should already be handled by the .travis.yml file. 10 | #[ $TRAVIS_OS_NAME != linux ] || { 11 | # sudo apt-get -y update || die 12 | # sudo apt-get -y install bsdtar autoconf-archive automake autoconf || die 13 | #} 14 | 15 | [ $TRAVIS_OS_NAME != osx ] || { 16 | brew install autoconf-archive || die 17 | } 18 | -------------------------------------------------------------------------------- /.travis/before_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | die() { 4 | echo " *** ERROR: " $* 5 | exit 1 6 | } 7 | 8 | set -x 9 | 10 | SUPPORTED_CONTIKI_REF=${SUPPORTED_CONTIKI_REF-1d69099} 11 | 12 | if [ $BUILD_PLATFORM = contiki ] 13 | then 14 | git clone git://github.com/contiki-os/contiki.git || die 15 | cd contiki || die 16 | git checkout ${SUPPORTED_CONTIKI_REF} || die 17 | cd .. || die 18 | fi 19 | 20 | exit 0 21 | -------------------------------------------------------------------------------- /.travis/deploy.prv.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darconeous/libnyoci/11a6e1b107cb1577cb0fffca7e3fd261f26da94a/.travis/deploy.prv.enc -------------------------------------------------------------------------------- /.travis/deploy.pub: -------------------------------------------------------------------------------- 1 | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJklIcnzvTSSq98mJ6PZGMPMtfXsXwH3m796tLRvl4bA9KCWkf6DlA0/mSVk7ZC+g9aEQcoTcjcs22RoISjXxOs= rquattle@rquattle-macpro.roam.corp.google.com 2 | -------------------------------------------------------------------------------- /.travis/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PREV_PATH="`pwd`" 4 | 5 | die() { 6 | echo " *** ERROR: " $* 7 | exit 1 8 | } 9 | 10 | if [ $BUILD_PLATFORM = unix ] 11 | then 12 | [ -e configure ] || ./bootstrap.sh || die 13 | 14 | mkdir -p "${BUILD_MAKEPATH}" || die 15 | 16 | cd "${BUILD_MAKEPATH}" || die 17 | 18 | ../configure --disable-dependency-tracking ${BUILD_CONFIGFLAGS} || die 19 | 20 | cd "${PREV_PATH}" || die 21 | fi 22 | 23 | make -C "${BUILD_MAKEPATH}" ${BUILD_MAKEARGS} || die 24 | -------------------------------------------------------------------------------- /.uncrustify.cfg: -------------------------------------------------------------------------------- 1 | 2 | indent_with_tabs = 1 # 1=indent to level only, 2=indent with tabs 3 | input_tab_size = 4 # original tab size 4 | output_tab_size = 4 # new tab size 5 | indent_columns = output_tab_size 6 | 7 | indent_label = 1 # pos: absolute col, neg: relative column 8 | nl_max = 3 9 | # 10 | # inter-symbol newlines 11 | # 12 | 13 | nl_enum_brace = remove # "enum {" vs "enum \n {" 14 | nl_union_brace = remove # "union {" vs "union \n {" 15 | nl_struct_brace = remove # "struct {" vs "struct \n {" 16 | nl_do_brace = remove # "do {" vs "do \n {" 17 | nl_if_brace = remove # "if () {" vs "if () \n {" 18 | nl_for_brace = remove # "for () {" vs "for () \n {" 19 | nl_else_brace = remove # "else {" vs "else \n {" 20 | nl_while_brace = remove # "while () {" vs "while () \n {" 21 | nl_switch_brace = remove # "switch () {" vs "switch () \n {" 22 | nl_brace_while = remove # "} while" vs "} \n while" - cuddle while 23 | nl_brace_else = remove # "} else" vs "} \n else" - cuddle else 24 | sp_brace_else = force 25 | sp_else_brace = force 26 | nl_func_var_def_blk = 1 27 | nl_fcall_brace = remove # "list_for_each() {" vs "list_for_each()\n{" 28 | nl_fdef_brace = remove # "int foo() {" vs "int foo()\n{" 29 | # nl_after_return = TRUE; 30 | # nl_before_case = 1 31 | 32 | 33 | code_width = 75 34 | nl_func_leave_one_liners = true 35 | ls_func_split_full = true 36 | ls_for_split_full = true 37 | 38 | 39 | nl_func_def_start = force 40 | nl_func_def_start_single = remove 41 | 42 | nl_func_decl_start = force 43 | nl_func_decl_start_single = remove 44 | 45 | nl_func_def_end = force 46 | nl_func_def_end_single = remove 47 | 48 | nl_after_func_proto = 1 49 | nl_after_func_proto_group = 1 50 | 51 | 52 | 53 | # 54 | # Source code modifications 55 | # 56 | 57 | mod_paren_on_return = remove # "return 1;" vs "return (1);" 58 | #mod_full_brace_if = remove # "if (a) a--;" vs "if (a) { a--; }" 59 | mod_full_brace_if_chain = true 60 | mod_full_brace_for = ignore # "for () a--;" vs "for () { a--; }" 61 | mod_full_brace_do = ignore # "do a--; while ();" vs "do { a--; } while ();" 62 | mod_full_brace_while = ignore # "while (a) a--;" vs "while (a) { a--; }" 63 | mod_full_brace_nl = 3 # don't remove if more than 3 newlines 64 | 65 | 66 | # 67 | # inter-character spacing options 68 | # 69 | sp_return_paren = force # "return (1);" vs "return(1);" 70 | sp_sizeof_paren = remove # "sizeof (int)" vs "sizeof(int)" 71 | sp_before_sparen = remove # "if (" vs "if(" 72 | sp_after_sparen = force # "if () {" vs "if (){" 73 | sp_after_cast = remove # "(int) a" vs "(int)a" 74 | sp_inside_braces = force # "{ 1 }" vs "{1}" 75 | sp_inside_braces_struct = force # "{ 1 }" vs "{1}" 76 | sp_inside_braces_enum = force # "{ 1 }" vs "{1}" 77 | sp_assign = force 78 | sp_arith = force 79 | sp_bool = force 80 | sp_compare = force 81 | sp_assign = force 82 | sp_after_comma = force 83 | sp_func_def_paren = remove # "int foo (){" vs "int foo(){" 84 | sp_func_call_paren = remove # "foo (" vs "foo(" 85 | sp_func_proto_paren = remove # "int foo ();" vs "int foo();" 86 | 87 | sp_before_ptr_star = ignore 88 | sp_after_ptr_star = ignore 89 | 90 | 91 | # 92 | # Aligning stuff 93 | # 94 | 95 | align_with_tabs = TRUE # use tabs to align 96 | align_on_tabstop = TRUE # align on tabstops 97 | # align_keep_tabs = true 98 | align_enum_equ_span = 4 # '=' in enum definition 99 | # align_nl_cont = TRUE 100 | # align_var_def_span = 2 101 | # align_var_def_inline = TRUE 102 | # align_var_def_star = FALSE 103 | # align_var_def_colon = TRUE 104 | # align_assign_span = 1 105 | align_struct_init_span = 3 # align stuff in a structure init '= { }' 106 | align_right_cmt_span = 3 107 | # align_pp_define_span = 8; 108 | # align_pp_define_gap = 4; 109 | 110 | cmt_star_cont = false 111 | 112 | # indent_brace = 0 113 | 114 | nl_func_paren = remove 115 | #nl_func_decl_start = ignore 116 | #nl_func_decl_empty = remove 117 | #nl_func_decl_args = remove 118 | #nl_func_decl_end = remove 119 | sp_inside_paren = remove 120 | sp_inside_square = remove 121 | sp_inside_paren_cast = remove 122 | sp_inside_fparen = remove 123 | sp_inside_sparen = remove 124 | sp_paren_paren = remove 125 | sp_between_ptr_star = remove 126 | align_func_params = true 127 | align_var_struct_span = 6 128 | 129 | eat_blanks_after_open_brace = true 130 | eat_blanks_before_close_brace = true 131 | pp_indent = ignore 132 | 133 | indent_continue = 4 134 | 135 | nl_start_of_file = remove 136 | nl_end_of_file = force 137 | nl_end_of_file_min = 1 138 | nl_comment_func_def = 1 139 | 140 | align_var_def_star_style = 0 141 | 142 | nl_define_macro = true 143 | indent_func_call_param = true 144 | indent_func_def_param = true 145 | indent_func_proto_param = true 146 | indent_var_def_cont = true 147 | indent_paren_close = 2 148 | sp_fparen_brace = force 149 | #align_nl_cont = true 150 | nl_multi_line_define = true 151 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darconeous/libnyoci/11a6e1b107cb1577cb0fffca7e3fd261f26da94a/CHANGELOG -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to LibNyoci 2 | ==================== 3 | 4 | First, thanks for considering contributing to LibNyoci! 5 | 6 | In general, there are three types of direct contributions to the project: 7 | 8 | 1. [Indirect Contributions](#indirect-contributions) (Bug Reports and 9 | Feature Requests) 10 | 2. [Trivial Direct Contributions](#trivial-direct-contributions) 11 | 3. [Substantial Direct Contributions](#substantial-direct-contributions) 12 | 13 | ## Indirect Contributions ## 14 | 15 | Anyone may file a bug report or a feature request to the [LibNyoci Issue 16 | Tracker](https://github.com/darconeous/libnyoci/issues). 17 | 18 | By submitting a feature request (particularly for novel features), you 19 | agree to not assert any patent or copyright infringement claims against 20 | the authors or users of the project for implementing the feature you 21 | requested. 22 | 23 | ## Trivial Direct Contributions ## 24 | 25 | You make a trivial direct contribution when you file a pull request against 26 | the project that addresses any of the following sorts of issues: 27 | 28 | * Misspellings 29 | * Syntax errors 30 | * Typos 31 | * Logic errors where the intended correct behavior was obvious 32 | * Simple platform build fixes 33 | * Code style and whitespace corrections 34 | 35 | These are the sorts of issues where, if you had filed a bug, the official 36 | developer would have solved it in exactly the same manner. More explicitly, 37 | if the change could be considered to have any significant creative latitude, 38 | then it is not a "Trivial Direct Contribution". 39 | 40 | When you submit such a pull request, you are agreeing to make no claim of 41 | copyright over the affected code. We allow for such pull requests because 42 | it is a convenient way to track and provide attribution for such fixes 43 | in release notes. 44 | 45 | If this policy is unacceptable, please do not file a pull request for 46 | trivial changes and instead [file a issue][1] so that one of the official 47 | developers address the problem instead. 48 | 49 | [1]: https://github.com/darconeous/libnyoci/issues 50 | 51 | ## Substantial Direct Contributions ## 52 | 53 | You make a substantial direct contribution when you file a pull request 54 | against LibNyoci that would be considered any of the following: 55 | 56 | * Implementing a new feature 57 | * Rewriting a paragraph to improve clarity 58 | * Fixing a non-trivial bug 59 | * Any change that could be considered to be creative 60 | 61 | By making such a contribution, you assert the following: 62 | 63 | 1. You wrote these changes in their entirety. 64 | 2. You hold the copyright to the changes. 65 | 3. You agree to irrevocably permit the changes to be distributed under the 66 | terms of the project's [open-source license](./LICENSE). 67 | 4. To the best of your knowledge, there are no legal impediments to 68 | including the changes into the master branch of the project. 69 | 70 | When making a substantial direct contribution, you may optionally update 71 | the Copyright notice to reflect your contribution. When your contribution 72 | includes an entirely new file, you should update the copyright line in the 73 | license boilerplate to indicate the copyright holder's name. 74 | -------------------------------------------------------------------------------- /HACKING.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ### Command to get all public API symbols ### 5 | 6 | find . -name '*.[ch]' | xargs cat | grep ^NYOCI_API_EXTERN | sed 's/.* \([a-zA-Z0-9_]*\)(.*/\1/;s/.* \([a-zA-Z0-9_]*\);/\1/' | sort -u 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | License 2 | ======= 3 | 4 | LibNyoci is distributed under the MIT License, which applies 5 | to all files distributed with this project unless specifically 6 | specified otherwise. 7 | 8 | Additionally, the application of this license is specifically 9 | excluded from all subdirectories of `third_party`. Use of these 10 | files are covered by their own individual licenses. 11 | 12 | Copyright (C) 2017 Robert Quattlebaum, et al. 13 | 14 | Permission is hereby granted, free of charge, to any person 15 | obtaining a copy of this software and associated 16 | documentation files (the "Software"), to deal in the 17 | Software without restriction, including without limitation 18 | the rights to use, copy, modify, merge, publish, distribute, 19 | sublicense, and/or sell copies of the Software, and to 20 | permit persons to whom the Software is furnished to do so, 21 | subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall 24 | be included in all copies or substantial portions of the 25 | Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 28 | KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 29 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 30 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 31 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 32 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 33 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 34 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | ACLOCAL_AMFLAGS = -I m4 3 | SUBDIRS = src doc 4 | 5 | DISTCLEANFILES = config.log config.status Makefile libtool make.out 6 | 7 | EXTRA_DIST = bootstrap.sh README.md NEWS.md CHANGELOG LICENSE etc/Dockerfile etc/build-in-docker.sh etc/run-in-docker.sh CONTRIBUTING.md .default-version 8 | 9 | # Metafiles 10 | EXTRA_DIST += .gitignore .uncrustify.cfg .travis.yml 11 | 12 | # Make sure the contiki bits make it into the archive. 13 | EXTRA_DIST += contiki-src/examples/nyoci-simple/.gitignore contiki-src/examples/nyoci-simple/Makefile contiki-src/examples/nyoci-simple/nyoci-simple.c 14 | EXTRA_DIST += contiki-src/examples/nyoci-plugtest/.gitignore contiki-src/examples/nyoci-plugtest/Makefile contiki-src/examples/nyoci-plugtest/nyoci-plugtest.c 15 | EXTRA_DIST += contiki-src/examples/nyoci-complex/.gitignore contiki-src/examples/nyoci-complex/Makefile contiki-src/examples/nyoci-complex/nyoci-complex.c 16 | EXTRA_DIST += contiki-src/led-node.c contiki-src/led-node.h contiki-src/Makefile.nyoci contiki-src/sensor-node.c contiki-src/sensor-node.h contiki-src/nyoci-task.c contiki-src/nyoci-task.h contiki-src/nyoci-contiki-config.h 17 | 18 | 19 | HASH_VERSION = $(shell \ 20 | git describe --dirty --match __poison__ --always 2> /dev/null \ 21 | ) 22 | 23 | EXTRA_VERSION = $(shell \ 24 | git describe --all --contains 016765d4b7f23d25d97ba2670ee00cba13934ba8 1> /dev/null 2> /dev/null \ 25 | && (test "`git describe 2> /dev/null | sed 's:^full/::'`" = $(VERSION) || echo -g$(HASH_VERSION)) \ 26 | ) 27 | 28 | distdir = $(PACKAGE)-$(VERSION)$(EXTRA_VERSION) 29 | 30 | @CODE_COVERAGE_RULES@ 31 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | Release Notes 2 | ============= 3 | 4 | This file contains a reverse-chronological list of releases and their associated 5 | changes. 6 | 7 | ## Version 0.07.00 ## 8 | 9 | * Initial release, based on commit `1a4bcd98a29326f7d5b5b819d2b37add675243bf` of 10 | [SMCP](https://github.com/darconeous/smcp) 11 | -------------------------------------------------------------------------------- /Xcode/macOS/nyoci-config.h: -------------------------------------------------------------------------------- 1 | /* src/libnyoci/nyoci-config.h. Generated from nyoci-config.h.in by configure. */ 2 | /*! @file nyoci-config.h 3 | ** @author Robert Quattlebaum 4 | ** @brief LibNyoci Build Options 5 | ** 6 | ** Copyright (C) 2017 Robert Quattlebaum 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person 9 | ** obtaining a copy of this software and associated 10 | ** documentation files (the "Software"), to deal in the 11 | ** Software without restriction, including without limitation 12 | ** the rights to use, copy, modify, merge, publish, distribute, 13 | ** sublicense, and/or sell copies of the Software, and to 14 | ** permit persons to whom the Software is furnished to do so, 15 | ** subject to the following conditions: 16 | ** 17 | ** The above copyright notice and this permission notice shall 18 | ** be included in all copies or substantial portions of the 19 | ** Software. 20 | ** 21 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 22 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 23 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 24 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 25 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 26 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 27 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | 31 | /* #undef NYOCI_EMBEDDED */ 32 | 33 | /* #undef NYOCI_SINGLETON */ 34 | 35 | /* #undef NYOCI_PLAT_NET_POSIX_FAMILY */ 36 | 37 | #define NYOCI_PLAT_NET posix 38 | 39 | /* #undef NYOCI_PLAT_TLS */ 40 | 41 | /* #undef NYOCI_AVOID_MALLOC */ 42 | 43 | /* #undef NYOCI_AVOID_PRINTF */ 44 | 45 | /* #undef NYOCI_DEFAULT_PORT */ 46 | 47 | /* #undef NYOCI_CONF_DUPE_BUFFER_SIZE */ 48 | 49 | /* #undef NYOCI_CONF_ENABLE_VHOSTS */ 50 | 51 | /* #undef NYOCI_CONF_MAX_ALLOCED_NODES */ 52 | 53 | /* #undef NYOCI_CONF_MAX_GROUPS */ 54 | 55 | /* #undef NYOCI_CONF_MAX_OBSERVERS */ 56 | 57 | /* #undef NYOCI_CONF_MAX_PAIRINGS */ 58 | 59 | /* #undef NYOCI_CONF_MAX_TIMEOUT */ 60 | 61 | /* #undef NYOCI_CONF_NODE_ROUTER */ 62 | 63 | /* #undef NYOCI_CONF_TRANS_ENABLE_BLOCK2 */ 64 | 65 | /* #undef NYOCI_CONF_TRANS_ENABLE_OBSERVING */ 66 | 67 | /* #undef NYOCI_CONF_USE_DNS */ 68 | 69 | /* #undef NYOCI_ADD_NEWLINES_TO_LIST_OUTPUT */ 70 | 71 | /* #undef NYOCI_ASYNC_RESPONSE_MAX_LENGTH */ 72 | 73 | /* #undef NYOCI_DEBUG_INBOUND_DROP_PERCENT */ 74 | 75 | /* #undef NYOCI_DEBUG_OUTBOUND_DROP_PERCENT */ 76 | 77 | /* #undef NYOCI_MAX_CASCADE_COUNT */ 78 | 79 | /* #undef NYOCI_MAX_CONTENT_LENGTH */ 80 | 81 | /* #undef NYOCI_MAX_OBSERVERS */ 82 | 83 | /* #undef NYOCI_MAX_PACKET_LENGTH */ 84 | 85 | /* #undef NYOCI_MAX_PATH_LENGTH */ 86 | 87 | /* #undef NYOCI_MAX_URI_LENGTH */ 88 | 89 | /* #undef NYOCI_MAX_VHOSTS */ 90 | 91 | /* #undef NYOCI_TRANSACTION_BURST_COUNT */ 92 | 93 | /* #undef NYOCI_TRANSACTION_BURST_TIMEOUT_MAX */ 94 | 95 | /* #undef NYOCI_TRANSACTION_BURST_TIMEOUT_MIN */ 96 | 97 | /* #undef NYOCI_THREAD_SAFE */ 98 | 99 | /* #undef NYOCI_NODE_ROUTER_USE_BTREE */ 100 | 101 | /* #undef NYOCI_OBSERVATION_DEFAULT_MAX_AGE */ 102 | 103 | /* #undef NYOCI_OBSERVATION_KEEPALIVE_INTERVAL */ 104 | 105 | /* #undef NYOCI_OBSERVER_CON_EVENT_EXPIRATION */ 106 | 107 | /* #undef NYOCI_OBSERVER_NON_EVENT_EXPIRATION */ 108 | 109 | /* #undef NYOCI_TRANSACTIONS_USE_BTREE */ 110 | 111 | /* #undef NYOCI_TRANSACTION_BURST_COUNT */ 112 | 113 | /* #undef NYOCI_TRANSACTION_POOL_SIZE */ 114 | 115 | /* #undef NYOCI_USE_CASCADE_COUNT */ 116 | 117 | /* #undef NYOCI_VARIABLE_MAX_KEY_LENGTH */ 118 | 119 | /* #undef NYOCI_VARIABLE_MAX_VALUE_LENGTH */ 120 | 121 | #define NYOCI_INTERNAL_EXTERN __attribute__((visibility("default"))) extern 122 | 123 | #define NYOCI_API_EXTERN __attribute__((visibility("default"))) extern 124 | 125 | /* #undef NYOCI_DEPRECATED */ 126 | -------------------------------------------------------------------------------- /Xcode/nyoci.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Xcode/nyoci.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Xcode/nyoci.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | die() { 4 | echo " *** $1 failed with error code $?" 5 | exit 1 6 | } 7 | 8 | cd "`dirname $0`" 9 | 10 | mkdir -p m4 11 | 12 | AUTOMAKE=automake\ --foreign autoreconf --verbose --force --install || die autoreconf 13 | 14 | echo 15 | echo Success. 16 | -------------------------------------------------------------------------------- /contiki-src/Makefile.nyoci: -------------------------------------------------------------------------------- 1 | ifndef NYOCI_ROOT 2 | ${error NYOCI_ROOT not defined! You must specify where LibNyoci resides} 3 | endif 4 | 5 | PROJECT_SOURCEFILES += nyoci.c nyoci-inbound.c nyoci-outbound.c \ 6 | nyoci-plat-net.c nyoci-observable.c nyoci-timer.c nyoci-transaction.c \ 7 | nyoci-dupe.c nyoci-missing.c nyoci-session.c nyoci-async.c 8 | PROJECT_SOURCEFILES += coap.c 9 | PROJECT_SOURCEFILES += url-helpers.c 10 | PROJECT_SOURCEFILES += string-utils.c 11 | PROJECT_SOURCEFILES += fasthash.c 12 | PROJECT_SOURCEFILES += nyoci-task.c 13 | 14 | # Missing function replacements 15 | MISSING_FUNCS = strlcat strlcpy 16 | PROJECT_SOURCEFILES += $(addsuffix .c,$(MISSING_FUNCS)) 17 | CFLAGS += $(foreach func,$(MISSING_FUNCS), -include $(NYOCI_ROOT)/src/missing/$(func)/$(func).h) 18 | PROJECTDIRS += $(addprefix $(NYOCI_ROOT)/src/missing/,$(MISSING_FUNCS)) 19 | 20 | # Extras 21 | ifeq ($(NYOCI_CONF_EXTRAS),1) 22 | PROJECT_SOURCEFILES += nyoci-list.c nyoci-node-router.c 23 | PROJECT_SOURCEFILES += nyoci-var-handler.c 24 | PROJECTDIRS += $(NYOCI_ROOT)/src/libnyociextra 25 | endif 26 | 27 | ifeq ($(NYOCI_CONF_LED_NODE),1) 28 | PROJECT_SOURCEFILES += led-node.c 29 | endif 30 | 31 | ifeq ($(NYOCI_CONF_SENSOR_NODE),1) 32 | PROJECT_SOURCEFILES += sensor-node.c 33 | endif 34 | 35 | USING_LIBNYOCI = 1 36 | 37 | ifdef VERBOSE_DEBUG 38 | #CFLAGS += -DDEBUG=$(VERBOSE_DEBUG) -D_DEBUG=$(VERBOSE_DEBUG) 39 | CFLAGS += -DVERBOSE_DEBUG=$(VERBOSE_DEBUG) 40 | #CFLAGS += -DUIP_CONF_LOGGING=$(VERBOSE_DEBUG) 41 | endif 42 | 43 | CFLAGS += -DNYOCI_CONFIG_OPTIONS_HEADER='"nyoci-contiki-config.h"' 44 | CFLAGS += -DUIP_CONF_BROADCAST=1 45 | #CFLAGS += -DUIP_UDP_SEND_UNREACH_NOPORT=1 46 | #CFLAGS += -DUIP_CONF_ICMP_DEST_UNREACH=1 47 | WFLAGS += -Wno-unknown-pragmas -Wno-unused-label 48 | 49 | CFLAGS += -I$(NYOCI_ROOT)/src 50 | CFLAGS += -I$(NYOCI_ROOT)/src/libnyoci 51 | CFLAGS += -I$(NYOCI_ROOT)/src/plat-net/uip 52 | CFLAGS += -I$(NYOCI_ROOT)/contiki-src 53 | 54 | PROJECTDIRS += $(NYOCI_ROOT)/src 55 | PROJECTDIRS += $(NYOCI_ROOT)/src/libnyoci 56 | PROJECTDIRS += $(NYOCI_ROOT)/src/plat-net/uip 57 | PROJECTDIRS += $(NYOCI_ROOT)/contiki-src 58 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-complex/.gitignore: -------------------------------------------------------------------------------- 1 | /obj_* 2 | /Makefile.target 3 | /*.minimal-net 4 | /*.native 5 | /contiki-*.a 6 | /symbols.c 7 | /symbols.h 8 | /*.hex 9 | /*.lib 10 | /*.a 11 | /*.avr-raven 12 | /*.cooja 13 | /*.banks 14 | /*.map 15 | /*.mem 16 | /*.lk 17 | /*.ihx 18 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-complex/Makefile: -------------------------------------------------------------------------------- 1 | CONTIKI_PROJECT = nyoci-complex 2 | 3 | ifeq ($(CONTIKI),) 4 | CONTIKI = ../../../../contiki 5 | endif 6 | 7 | NYOCI_ROOT = ../../.. 8 | 9 | NYOCI_CONF_SENSOR_NODE = 1 10 | NYOCI_CONF_LED_NODE = 1 11 | NYOCI_CONF_EXTRAS = 1 12 | #VERBOSE_DEBUG = 0 13 | 14 | ifneq ($(UIP_CONF_IPV6),) 15 | CFLAGS += -DUIP_CONF_IPV6=$(UIP_CONF_IPV6) 16 | endif 17 | 18 | include $(NYOCI_ROOT)/contiki-src/Makefile.nyoci 19 | 20 | CLEAN += *.hex *.elf symbols.c symbols.h 21 | 22 | all: $(CONTIKI_PROJECT) 23 | 24 | include $(CONTIKI)/Makefile.include 25 | 26 | ifeq ($(CC),sdcc) 27 | CFLAGS += --disable-warning 115 28 | endif 29 | 30 | burn: $(CONTIKI_PROJECT).u 31 | 32 | burn-eeprom: $(CONTIKI_PROJECT).u-eep 33 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-plugtest/.gitignore: -------------------------------------------------------------------------------- 1 | /obj_* 2 | /Makefile.target 3 | /*.minimal-net 4 | /*.native 5 | /contiki-*.a 6 | /symbols.c 7 | /symbols.h 8 | /*.hex 9 | /*.lib 10 | /*.a 11 | /*.avr-raven 12 | /*.cooja 13 | /*.banks 14 | /*.map 15 | /*.mem 16 | /*.lk 17 | /*.ihx 18 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-plugtest/Makefile: -------------------------------------------------------------------------------- 1 | CONTIKI_PROJECT = nyoci-plugtest 2 | 3 | ifeq ($(CONTIKI),) 4 | CONTIKI = ../../../../contiki 5 | endif 6 | 7 | NYOCI_ROOT = ../../.. 8 | 9 | ifneq ($(UIP_CONF_IPV6),) 10 | CFLAGS += -DUIP_CONF_IPV6=$(UIP_CONF_IPV6) 11 | endif 12 | 13 | NYOCI_CONF_EXTRAS = 1 14 | 15 | #VERBOSE_DEBUG = 0 16 | 17 | include $(NYOCI_ROOT)/contiki-src/Makefile.nyoci 18 | 19 | CONTIKI_SOURCEFILES += plugtest-server.c 20 | PROJECTDIRS += $(NYOCI_ROOT)/src/plugtest 21 | 22 | ifeq ($(TARGET),avr-raven) 23 | #APPS += raven-webserver 24 | APPS += raven-lcd-interface 25 | endif 26 | 27 | CLEAN += *.hex *.elf symbols.c symbols.h 28 | 29 | all: $(CONTIKI_PROJECT) 30 | 31 | include $(CONTIKI)/Makefile.include 32 | 33 | ifeq ($(CC),sdcc) 34 | CFLAGS += --disable-warning 115 35 | endif 36 | 37 | burn: $(CONTIKI_PROJECT).u 38 | 39 | burn-eeprom: $(CONTIKI_PROJECT).u-eep 40 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-plugtest/nyoci-plugtest.avr-raven.gdb: -------------------------------------------------------------------------------- 1 | file nyoci-plugtest.avr-raven 2 | set remote Z-packet enable 3 | #set remote step-over-range-packet enable 4 | target remote localhost:4242 5 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-plugtest/nyoci-plugtest.c: -------------------------------------------------------------------------------- 1 | /* @file nyoci-plugtest.c 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #include "nyoci-task.h" 30 | #include "watchdog.h" 31 | #include "net/ip/resolv.h" 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | PROCESS_NAME(nyoci_plugtest); 39 | PROCESS(nyoci_plugtest, "LibNyoci Plugtest"); 40 | 41 | AUTOSTART_PROCESSES( 42 | &resolv_process, 43 | &nyoci_task, 44 | &nyoci_plugtest, 45 | NULL 46 | ); 47 | 48 | PROCESS_THREAD(nyoci_plugtest, ev, data) 49 | { 50 | static struct plugtest_server_s plugtest_server; 51 | static struct nyoci_node_s root_node; 52 | 53 | // Set up the root node. 54 | nyoci_node_init(&root_node,NULL,NULL); 55 | 56 | // Set up the node router. 57 | nyoci_set_default_request_handler(nyoci, &nyoci_node_router_handler, &root_node); 58 | 59 | PROCESS_BEGIN(); 60 | 61 | plugtest_server_init(&plugtest_server,&root_node); 62 | 63 | PROCESS_END(); 64 | } 65 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-simple/.gitignore: -------------------------------------------------------------------------------- 1 | /obj_* 2 | /Makefile.target 3 | /*.minimal-net 4 | /*.native 5 | /contiki-*.a 6 | /symbols.c 7 | /symbols.h 8 | /*.hex 9 | /*.lib 10 | /*.a 11 | /*.avr-raven 12 | /*.cooja 13 | /*.banks 14 | /*.map 15 | /*.mem 16 | /*.lk 17 | /*.ihx 18 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-simple/Makefile: -------------------------------------------------------------------------------- 1 | CONTIKI_PROJECT = nyoci-simple 2 | 3 | ifeq ($(CONTIKI),) 4 | CONTIKI = ../../../../contiki 5 | endif 6 | 7 | NYOCI_ROOT = ../../.. 8 | 9 | NYOCI_CONF_EXTRAS = 0 10 | #VERBOSE_DEBUG = 0 11 | 12 | ifneq ($(UIP_CONF_IPV6),) 13 | CFLAGS += -DUIP_CONF_IPV6=$(UIP_CONF_IPV6) 14 | endif 15 | 16 | include $(NYOCI_ROOT)/contiki-src/Makefile.nyoci 17 | 18 | CLEAN += *.hex *.elf symbols.c symbols.h 19 | 20 | all: $(CONTIKI_PROJECT) 21 | 22 | include $(CONTIKI)/Makefile.include 23 | 24 | ifeq ($(CC),sdcc) 25 | CFLAGS += --disable-warning 115 26 | endif 27 | 28 | burn: $(CONTIKI_PROJECT).u 29 | 30 | burn-eeprom: $(CONTIKI_PROJECT).u-eep 31 | -------------------------------------------------------------------------------- /contiki-src/examples/nyoci-simple/nyoci-simple.c: -------------------------------------------------------------------------------- 1 | /* @file nyoci-simple.c 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #include "nyoci-task.h" 30 | #include "net/ip/resolv.h" 31 | #include 32 | 33 | PROCESS_NAME(nyoci_simple); 34 | PROCESS(nyoci_simple, "LibNyoci Simple Demo"); 35 | 36 | /*---------------------------------------------------------------------------*/ 37 | AUTOSTART_PROCESSES( 38 | &resolv_process, 39 | &nyoci_task, 40 | &nyoci_simple, 41 | NULL 42 | ); 43 | 44 | /*---------------------------------------------------------------------------*/ 45 | static nyoci_status_t 46 | request_handler(void* context) { 47 | /* This will respond to every GET request to `/hello-world' with 48 | ** "Hello world!". Everyone else gets a 4.04 Not Found. */ 49 | 50 | printf("Got a request!\n"); 51 | 52 | if(nyoci_inbound_get_code() != COAP_METHOD_GET) { 53 | return NYOCI_STATUS_NOT_IMPLEMENTED; 54 | } 55 | 56 | while(nyoci_inbound_peek_option(NULL, NULL) != COAP_OPTION_URI_PATH) 57 | if(nyoci_inbound_next_option(NULL, NULL) == COAP_OPTION_INVALID) 58 | break; 59 | 60 | if(nyoci_inbound_option_strequal(COAP_OPTION_URI_PATH, "hello-world")) { 61 | 62 | nyoci_outbound_begin_response(COAP_RESULT_205_CONTENT); 63 | 64 | nyoci_outbound_add_option_uint( 65 | COAP_OPTION_CONTENT_TYPE, 66 | COAP_CONTENT_TYPE_TEXT_PLAIN 67 | ); 68 | 69 | nyoci_outbound_append_content("Hello world!", NYOCI_CSTR_LEN); 70 | 71 | return nyoci_outbound_send(); 72 | } else if(nyoci_inbound_option_strequal(COAP_OPTION_URI_PATH, ".well-known")) { 73 | nyoci_inbound_next_option(NULL, NULL); 74 | 75 | if(nyoci_inbound_option_strequal(COAP_OPTION_URI_PATH, "core")) { 76 | nyoci_outbound_begin_response(COAP_RESULT_205_CONTENT); 77 | 78 | nyoci_outbound_add_option_uint( 79 | COAP_OPTION_CONTENT_TYPE, 80 | COAP_CONTENT_TYPE_APPLICATION_LINK_FORMAT 81 | ); 82 | 83 | nyoci_outbound_append_content("", NYOCI_CSTR_LEN); 84 | 85 | return nyoci_outbound_send(); 86 | } 87 | } 88 | 89 | return NYOCI_STATUS_NOT_FOUND; 90 | } 91 | 92 | /*---------------------------------------------------------------------------*/ 93 | PROCESS_THREAD(nyoci_simple, ev, data) 94 | { 95 | PROCESS_BEGIN(); 96 | 97 | nyoci_set_default_request_handler(instance, &request_handler, NULL); 98 | 99 | PROCESS_END(); 100 | } 101 | -------------------------------------------------------------------------------- /contiki-src/led-node.c: -------------------------------------------------------------------------------- 1 | /* @file led-node.c 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #include "led-node.h" 30 | #include "assert-macros.h" 31 | #include "dev/leds.h" 32 | #include 33 | 34 | nyoci_status_t 35 | led_var_func( 36 | nyoci_var_handler_t node, 37 | uint8_t action, 38 | uint8_t i, 39 | char* value 40 | ) { 41 | nyoci_status_t ret = 0; 42 | uint8_t mask = (1< 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_led_node_h 30 | #define NYOCI_led_node_h 31 | 32 | #include "contiki.h" 33 | #include 34 | #include 35 | #include "dev/leds.h" 36 | 37 | nyoci_status_t 38 | led_var_func( 39 | nyoci_var_handler_t node, 40 | uint8_t action, 41 | uint8_t i, 42 | char* value 43 | ); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /contiki-src/nyoci-contiki-config.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-contiki-config.h 2 | ** @author Robert Quattlebaum 3 | ** @brief LibNyoci Build Options 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef __NYOCI_CONTIKI_CONFIG_H__ 31 | #define __NYOCI_CONTIKI_CONFIG_H__ 32 | 33 | /*****************************************************************************/ 34 | // MARK: - LibNyoci Build Parameters 35 | 36 | #define NYOCI_EMBEDDED 1 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /contiki-src/nyoci-task.c: -------------------------------------------------------------------------------- 1 | /* @file nyoci-task.c 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #include "contiki.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #include "nyoci-task.h" 37 | 38 | #include "net/ip/uip.h" 39 | #include "net/ip/uip-udp-packet.h" 40 | #include "sys/clock.h" 41 | #include "watchdog.h" 42 | 43 | #if DEBUG 44 | #include 45 | #if __AVR__ 46 | #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) 47 | #else 48 | #define PRINTF(...) printf(__VA_ARGS__) 49 | #endif 50 | #else 51 | #define PRINTF(...) 52 | #endif 53 | 54 | #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 55 | 56 | #if UIP_CONF_IPV6 57 | #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) 58 | #else 59 | #define UIP_UDP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) 60 | #endif 61 | 62 | PROCESS(nyoci_task, "CoAP Daemon"); 63 | 64 | PROCESS_THREAD(nyoci_task, ev, data) 65 | { 66 | static struct etimer et; 67 | 68 | PROCESS_BEGIN(); 69 | 70 | NYOCI_LIBRARY_VERSION_CHECK(); 71 | 72 | PRINTF("Starting LibNyoci\n"); 73 | 74 | if(!nyoci_create()) { 75 | PRINTF("Failed to start LibNyoci\n"); 76 | goto bail; 77 | } 78 | 79 | if(!nyoci_plat_bind_to_port(nyoci, NYOCI_SESSION_TYPE_UDP, NYOCI_DEFAULT_PORT)) { 80 | PRINTF("Failed to bind to port\n"); 81 | goto bail; 82 | } 83 | 84 | if(!nyoci_plat_get_udp_conn(nyoci)) { 85 | PRINTF("LibNyoci failed to create UDP conneciton!\n"); 86 | goto bail; 87 | } 88 | 89 | PRINTF("LibNyoci started. UDP Connection = %p\n",nyoci_plat_get_udp_conn(nyoci)); 90 | 91 | etimer_set(&et, 1); 92 | 93 | while(1) { 94 | PROCESS_WAIT_EVENT(); 95 | 96 | if(ev == tcpip_event) { 97 | nyoci_plat_process(nyoci); 98 | etimer_set(&et, CLOCK_SECOND*nyoci_get_timeout(nyoci)/MSEC_PER_SEC+1); 99 | } 100 | 101 | if(etimer_expired(&et)) { 102 | tcpip_poll_udp(nyoci_plat_get_udp_conn(nyoci)); 103 | } else { 104 | etimer_set(&et, CLOCK_SECOND*nyoci_get_timeout(nyoci)/MSEC_PER_SEC+1); 105 | } 106 | } 107 | 108 | bail: 109 | PRINTF("Stopping LibNyoci\n"); 110 | PROCESS_END(); 111 | } 112 | -------------------------------------------------------------------------------- /contiki-src/nyoci-task.h: -------------------------------------------------------------------------------- 1 | /* @file nyoci-task.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef __NYOCI_TASK_H__ 30 | #define __NYOCI_TASK_H__ 31 | 32 | #include "contiki.h" 33 | #include 34 | 35 | PROCESS_NAME(nyoci_task); 36 | 37 | CCIF extern struct nyoci_s gNyociInstance; 38 | #define nyoci &gNyociInstance 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /contiki-src/sensor-node.c: -------------------------------------------------------------------------------- 1 | /* @file sensor-node.c 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #include "sensor-node.h" 30 | #include "assert-macros.h" 31 | #include "lib/sensors.h" 32 | #include 33 | 34 | const extern struct sensors_sensor *sensors[]; 35 | 36 | nyoci_status_t 37 | sensor_var_func( 38 | nyoci_var_handler_t node, 39 | uint8_t action, 40 | uint8_t i, 41 | char* value 42 | ) { 43 | nyoci_status_t ret = 0; 44 | const struct sensors_sensor *sensor; 45 | static uint8_t sensor_count; 46 | 47 | if(!sensor_count) 48 | for(sensor_count = 0; sensors[sensor_count] != NULL; ++sensor_count) {} 49 | 50 | if(i>=sensor_count) { 51 | ret = NYOCI_STATUS_NOT_FOUND; 52 | goto bail; 53 | } 54 | 55 | sensor = sensors[i]; 56 | 57 | if(action==NYOCI_VAR_GET_KEY) { 58 | strcpy(value,sensor->type); 59 | } else if(action==NYOCI_VAR_GET_OBSERVABLE) { 60 | if(sensor->status && !sensor->status(SENSORS_ACTIVE)) 61 | return NYOCI_STATUS_NOT_IMPLEMENTED; 62 | } else if(action==NYOCI_VAR_GET_VALUE) { 63 | int32_to_dec_cstr(value,sensor->value(0)); 64 | } else if(action==NYOCI_VAR_SET_VALUE) { 65 | ret = NYOCI_STATUS_NOT_IMPLEMENTED; 66 | } else { 67 | ret = NYOCI_STATUS_NOT_IMPLEMENTED; 68 | } 69 | 70 | bail: 71 | return ret; 72 | } 73 | -------------------------------------------------------------------------------- /contiki-src/sensor-node.h: -------------------------------------------------------------------------------- 1 | /* @file sensor-node.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_sensor_node_h 30 | #define NYOCI_sensor_node_h 31 | 32 | #include "contiki.h" 33 | #include 34 | #include 35 | 36 | nyoci_status_t 37 | sensor_var_func( 38 | nyoci_var_handler_t node, 39 | uint8_t action, 40 | uint8_t i, 41 | char* value 42 | ); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | 3 | man_MANS = nyocictl.1 4 | 5 | EXTRA_DIST = nyocictl.1 oss-plan.md 6 | -------------------------------------------------------------------------------- /doc/nyocictl.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 11/28/2013 \" DATE 7 | .Dt nyocictl 1 \" Program name and manual section number 8 | .\".Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm nyocictl 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .\" Use .Nm macro to designate other names for the documented program. 14 | .Nd LibNyoci and CoAP command line tool 15 | .Sh SYNOPSIS \" Section Header - required - don't modify 16 | .Nm 17 | .Op Fl h 18 | .Op Fl d 19 | .Op Fl p Ar port 20 | .Op Fl f Ar filename 21 | .\".Op Ar file \" [file] 22 | .\".Op Ar \" [file ...] 23 | .Op Ar cmd Op Ar arg1 ... \" Underlined argument - use .Ar anywhere to underline 24 | .Sh DESCRIPTION \" Section Header - required - don't modify 25 | .Nm 26 | is a program for exploring, interacting with, and configuring CoAP devices. 27 | .Nm 28 | supports taking subcommands on the command line, interactively, or even redirected from standard input. 29 | A great deal of additional information can be found in the online help via the help command. 30 | .\" Underlining is accomplished with the .Ar macro like this: 31 | .\" .Ar underlined text . 32 | .\" .Pp \" Inserts a space 33 | .\" 34 | .Sh SUBCOMMANDS 35 | .Bl -tag -width -indent 36 | .\" 37 | .It Xo Ar help Op Ar subcommand 38 | .Xc 39 | With no argument, this command lists all of the subcommands supported by 40 | .Nm 41 | . If a subcommand is used as an argument, help is displayed for that subcommand. 42 | .\" 43 | .It Xo Ar get Op Ar url 44 | .Xc 45 | Performs a CoAP GET on the specified URL, displaying the resulting contents. 46 | If 47 | .Ar url 48 | is unspecified, the current path URL is used instead. 49 | .\" 50 | .It Xo Ar cat 51 | .Xc 52 | Alias for get. 53 | .\" 54 | .It Xo Ar list Op Ar url 55 | .Xc 56 | Lists the contents of the specified URL in a human-readable format. 57 | If 58 | .Ar url 59 | is unspecified, the current path URL is used instead. 60 | .\" 61 | .It Xo Ar ls 62 | .Xc 63 | Alias for list. 64 | .\" 65 | .It Xo Ar post Op Ar url Op Ar contents 66 | .Xc 67 | Performs a CoAP POST on the specified URL, optionally using the value of 68 | .Ar contents 69 | as the content of the request. Results are displayed similar to how GET operates. 70 | If 71 | .Ar url 72 | is unspecified, the current path URL is used instead. 73 | .\" 74 | .It Xo Ar delete Op Ar url 75 | .Xc 76 | Performs a CoAP DELETE on the specified URL. Results are displayed similar to how GET operates. 77 | If 78 | .Ar url 79 | is unspecified, the current path URL is used instead. 80 | .\" 81 | .It Xo Ar rm 82 | .Xc 83 | Alias for delete. 84 | .\" 85 | .It Xo Ar cd Op Ar url 86 | .Xc 87 | Change the current path URL, if specified. Otherwise simply displays the current URL. 88 | .\" 89 | .El \" Ends the list 90 | .\" 91 | .\" 92 | .\" 93 | .Sh ENVIRONMENT \" May not be needed 94 | .Bl -tag -width -indent 95 | .It Ev NYOCI_CURRENT_PATH 96 | Informs 97 | .Nm 98 | what URL to use as the initial path. 99 | .It Ev NYOCI_HISTORY_FILE 100 | Informs 101 | .Nm 102 | where to store command history when used in interactive mode. 103 | .It Ev COAP_PROXY_URL 104 | Informs 105 | .Nm 106 | which proxy it should use to satisfy requests it cannot satisfy directly. 107 | .El \" Ends the list 108 | .\" .El 109 | .\" .Sh FILES \" File used or created by the topic of the man page 110 | .\" .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 111 | .\" .It Pa /usr/share/file_name 112 | .\" FILE_1 description 113 | .\" .It Pa /Users/joeuser/Library/really_long_file_name 114 | .\" FILE_2 description 115 | .\" .El \" Ends the list 116 | .\" .Sh DIAGNOSTICS \" May not be needed 117 | .\" .Bl -diag 118 | .\" .It Diagnostic Tag 119 | .\" Diagnostic informtion here. 120 | .\" .It Diagnostic Tag 121 | .\" Diagnostic informtion here. 122 | .\" .El 123 | .\" .Sh SEE ALSO 124 | .\" List links in ascending order by section, alphabetically within a section. 125 | .\" Please do not reference files that do not exist without filing a bug report 126 | .\" .Xr a 1 , 127 | .\" .Xr b 1 , 128 | .\" .Xr c 1 , 129 | .\" .Xr a 2 , 130 | .\" .Xr b 2 , 131 | .\" .Xr a 3 , 132 | .\" .Xr b 3 133 | .\" .Sh BUGS \" Document known, unremedied bugs 134 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner 135 | -------------------------------------------------------------------------------- /etc/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcc 2 | 3 | RUN apt-get -y update \ 4 | && DEBIAN_FRONTEND=noninteractive \ 5 | apt-get install -y -q --no-install-recommends \ 6 | libreadline-dev \ 7 | libtool \ 8 | autoconf-archive \ 9 | net-tools \ 10 | usbutils \ 11 | vim \ 12 | man \ 13 | bsdtar \ 14 | gdb \ 15 | gcc g++ \ 16 | pkg-config 17 | -------------------------------------------------------------------------------- /etc/build-in-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Nest Labs, Inc. 4 | # All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | 20 | DIR="`dirname $0`" 21 | 22 | "${DIR}"/run-in-docker.sh -i 'DIR="`pwd`" && 23 | mkdir -p /build && 24 | cd /build && "${DIR}"/configure --enable-tls && 25 | make -j `nproc` check AM_DEFAULT_VERBOSITY=1 26 | ' || exit 1 27 | 28 | "${DIR}"/run-in-docker.sh -i 'DIR="`pwd`" && 29 | mkdir -p /build && 30 | cd /build && "${DIR}"/configure --enable-embedded NYOCI_CONF_TRANS_ENABLE_BLOCK2=1 NYOCI_CONF_TRANS_ENABLE_OBSERVING=1 && 31 | make -j `nproc` check AM_DEFAULT_VERBOSITY=1 32 | ' || exit 1 33 | 34 | "${DIR}"/run-in-docker.sh -i 'DIR="`pwd`" && 35 | mkdir -p /build && 36 | cd /build && "${DIR}"/configure && 37 | make -j `nproc` distcheck AM_DEFAULT_VERBOSITY=1 38 | ' || exit 1 39 | -------------------------------------------------------------------------------- /etc/libnyoci.rb: -------------------------------------------------------------------------------- 1 | require 'formula' 2 | 3 | class Libnyoci < Formula 4 | homepage 'https://github.com/darconeous/libnyoci' 5 | url 'https://github.com/darconeous/libnyoci.git', :tag => 'full/0.07.00rc1' 6 | head 'https://github.com/darconeous/libnyoci.git', :using => :git, :branch => 'master' 7 | sha256 '' 8 | version '0.07.00rc1' 9 | 10 | # depends_on 'readline' => :recommended 11 | # depends_on 'curl' => :recommended 12 | depends_on 'openssl@1.1' => :recommended 13 | 14 | if build.head? 15 | depends_on 'autoconf' => :build 16 | depends_on 'automake' => :build 17 | depends_on 'libtool' => :build 18 | end 19 | 20 | def install 21 | 22 | system "[ -x configure ] || PATH=\"#{HOMEBREW_PREFIX}/bin:$PATH\" ./bootstrap.sh" if build.head? 23 | system "./configure", 24 | "--disable-debug", 25 | "--disable-dependency-tracking", 26 | "--enable-tls", 27 | "--prefix=#{prefix}" 28 | system "make install" 29 | end 30 | 31 | def test 32 | system "nyocictl -p 10342 cat -i coap://localhost:10342/" 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /etc/run-in-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016 Nest Labs, Inc. 4 | # All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | set -e 20 | 21 | path_to_dir () 22 | { 23 | f=$@; 24 | if [ -d "$f" ]; then 25 | base=""; 26 | dir="$f"; 27 | else 28 | base="/$(basename "$f")"; 29 | dir=$(dirname "$f"); 30 | fi; 31 | dir=$(cd "$dir" && /bin/pwd); 32 | echo "$dir$base" 33 | } 34 | 35 | usage () 36 | { 37 | echo "usage: " 38 | echo "$0 [-i] " 39 | echo "$0 -c|--clear" 40 | echo "$0 -a|--clear-all" 41 | echo -n 42 | echo "-c, --clear delete all docker images including the current one" 43 | echo "--priv run container with privileges" 44 | echo "-p, --prune delete all docker images except the current one" 45 | echo "-i, --interactive run docker with -it" 46 | } 47 | 48 | calc_sha1 () 49 | { 50 | # Figure out which program to use to calculate 51 | # the SHA1 hash and execute it. 52 | if ( which shasum > /dev/null 2>&1 ) 53 | then shasum "$1" 54 | elif ( which sha1sum > /dev/null 2>&1 ) 55 | then sha1sum "$1" 56 | elif ( which openssl > /dev/null 2>&1 ) 57 | then openssl dgst -sha1 < "$1" 58 | fi 59 | } 60 | 61 | SCRIPT_DIR="$(path_to_dir "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")" 62 | PROJECT_DIR="$(pwd)" 63 | SRC_DIR="/src" 64 | 65 | # 1. Calculate the SHA1 hash of the Dockerfile 66 | DOCKER_SHA=$(calc_sha1 $SCRIPT_DIR/Dockerfile) 67 | DOCKER_SHORT_SHA=${DOCKER_SHA:0:8} 68 | DOCKER_IMAGE_NAME_BASE="nestlabs/wpantund-build" 69 | DOCKER_IMAGE_NAME="$DOCKER_IMAGE_NAME_BASE:$DOCKER_SHORT_SHA" 70 | 71 | prune_unused_dockers () 72 | { 73 | docker images | grep $DOCKER_IMAGE_NAME_BASE | awk 'BEGIN{OFS = ":"}{print $1,$2}' | grep -v $DOCKER_IMAGE_NAME | xargs -I {} docker rmi {} 74 | return 0 75 | } 76 | 77 | delete_current_docker () 78 | { 79 | docker rmi $DOCKER_IMAGE_NAME 80 | } 81 | 82 | delete_all_dockers () 83 | { 84 | prune_unused_dockers 85 | delete_current_docker 86 | rm -rf "$SCRIPT_DIR/hostinfo" 87 | } 88 | 89 | if [[ $# -eq 0 ]] 90 | then 91 | echo "Give me something to do." 92 | usage 93 | exit 0 94 | fi 95 | 96 | OTHER_OPTS="" 97 | 98 | # Check to see if we have any arguments to work on. 99 | while [[ $# > 0 ]] 100 | do 101 | key="$1" 102 | 103 | case $key in 104 | -h|--help) 105 | usage 106 | exit 0; 107 | ;; 108 | -c|--clear) 109 | delete_all_dockers 110 | exit $? 111 | ;; 112 | -p|--prune) 113 | prune_unused_dockers 114 | exit $? 115 | ;; 116 | --priv) 117 | OTHER_OPTS="${OTHER_OPTS} --privileged" 118 | ;; 119 | -i|--it) 120 | OTHER_OPTS="${OTHER_OPTS} -it" 121 | ;; 122 | -a|--args) 123 | shift 124 | OTHER_OPTS="${OTHER_OPTS} $1" 125 | ;; 126 | *) 127 | if [ ${key:0:1} == '-' ] 128 | then 129 | echo "Unknown option $key" 130 | usage 131 | exit 1 132 | fi 133 | break 134 | ;; 135 | esac 136 | shift 137 | done 138 | 139 | # 2. Check to see if that docker image exists. 140 | RESULT=$(docker images | awk 'BEGIN{OFS = ":"}{print $1,$2}' |grep -c $DOCKER_IMAGE_NAME) || true 141 | 142 | if [ $RESULT -eq 1 ]; then 143 | echo "Docker image $DOCKER_IMAGE_NAME already exists" 144 | else 145 | echo "Creating new docker image: $DOCKER_IMAGE_NAME" 146 | docker build -t $DOCKER_IMAGE_NAME $SCRIPT_DIR 147 | fi 148 | 149 | COMMAND="$@" 150 | TMPFILE="$(mktemp ./tmp.XXXXXXXXXX)" 151 | echo "$COMMAND" > "$TMPFILE" 152 | chmod 0755 "$TMPFILE" 153 | trap "rm -f '$TMPFILE'" EXIT 154 | echo "Executing '$COMMAND' as $USERNAME" 155 | 156 | CMD="docker run \ 157 | -v=$PROJECT_DIR:$SRC_DIR \ 158 | -w=$SRC_DIR \ 159 | --hostname=`hostname`\ 160 | --rm \ 161 | $OTHER_OPTS \ 162 | $DOCKER_IMAGE_NAME \ 163 | bash --login -ci '$TMPFILE'" 164 | 165 | $CMD 166 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | Makefile 3 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | DIST_SUBDIRS = missing @PLATFORM_SUBDIRS@ libnyoci libnyociextra nyocictl plugtest examples tests 2 | 3 | DISTCLEANFILES = .deps Makefile 4 | 5 | EXTRA_DIST = 6 | 7 | SUBDIRS = missing @NYOCI_PLAT_NET_DIR@ 8 | 9 | if NYOCI_PLAT_TLS 10 | SUBDIRS += @NYOCI_PLAT_TLS_DIR@ 11 | endif 12 | 13 | SUBDIRS += libnyoci 14 | 15 | if BUILD_LIBNYOCIEXTRA 16 | SUBDIRS += libnyociextra 17 | endif 18 | 19 | if BUILD_NYOCICTL 20 | SUBDIRS += nyocictl 21 | endif 22 | 23 | if BUILD_PLUGTEST 24 | SUBDIRS += plugtest 25 | endif 26 | 27 | if BUILD_EXAMPLES 28 | SUBDIRS += examples 29 | endif 30 | 31 | SUBDIRS += tests 32 | 33 | @CODE_COVERAGE_RULES@ 34 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 35 | AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) 36 | 37 | EXTRA_DIST += version.c.in version.h 38 | CLEANFILES = $(top_builddir)/$(subdir)/version.c 39 | SOURCE_VERSION=$(shell git describe --dirty --always --match "[0-9].*" 2> /dev/null) 40 | BUILT_SOURCES = $(top_builddir)/$(subdir)/version.c 41 | .INTERMEDIATE: $(top_builddir)/$(subdir)/version.c 42 | $(top_builddir)/$(subdir)/version.c: version.c.in Makefile 43 | sed 's/SOURCE_VERSION/"$(SOURCE_VERSION)"/' < $< > $@ 44 | -------------------------------------------------------------------------------- /src/examples/.gitignore: -------------------------------------------------------------------------------- 1 | example-1 2 | example-2 3 | example-3 4 | example-4 5 | example-multicast-request 6 | -------------------------------------------------------------------------------- /src/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | @CODE_COVERAGE_RULES@ 2 | 3 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 4 | AM_CFLAGS = $(CFLAGS) $(CODE_COVERAGE_CFLAGS) 5 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) $(MISSING_CPPFLAGS) 6 | 7 | noinst_PROGRAMS = \ 8 | example-1 \ 9 | example-2 \ 10 | example-3 \ 11 | example-4 \ 12 | example-multicast-request \ 13 | $(NULL) 14 | 15 | example_1_SOURCES = example-1.c 16 | example_1_LDADD = ../libnyoci/libnyoci.la 17 | 18 | example_2_SOURCES = example-2.c 19 | example_2_LDADD = ../libnyoci/libnyoci.la 20 | 21 | example_3_SOURCES = example-3.c 22 | example_3_LDADD = ../libnyoci/libnyoci.la ../libnyociextra/libnyociextra.la 23 | 24 | example_4_SOURCES = example-4.c 25 | example_4_LDADD = ../libnyoci/libnyoci.la ../libnyociextra/libnyociextra.la 26 | 27 | example_multicast_request_SOURCES = example-multicast-request.c 28 | example_multicast_request_LDADD = ../libnyoci/libnyoci.la 29 | 30 | DISTCLEANFILES = .deps Makefile 31 | -------------------------------------------------------------------------------- /src/examples/example-1.c: -------------------------------------------------------------------------------- 1 | /*! @page nyoci-example-1 example-1.c: Responding to a request 2 | ** 3 | ** This simple example shows how to respond to a request. 4 | ** 5 | ** @include example-1.c 6 | ** 7 | ** @sa @ref nyoci-instance, @ref nyoci-inbound, @ref nyoci-outbound 8 | ** 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | static nyoci_status_t 15 | request_handler(void* context) 16 | { 17 | /* This request handler will respond to every GET request with "Hello world!". 18 | * It isn't usually a good idea to (almost) completely ignore the actual 19 | * request, but since this is just an example we can get away with it. 20 | * We do more processing on the request in the other examples. */ 21 | 22 | printf("Got a request!\n"); 23 | 24 | // Only handle GET requests for now. Returning NYOCI_STATUS_NOT_IMPLEMENTED 25 | // here without sending a response will cause us to automatically 26 | // send a METHOD_NOT_IMPLEMENTED response. 27 | if(nyoci_inbound_get_code() != COAP_METHOD_GET) { 28 | return NYOCI_STATUS_NOT_IMPLEMENTED; 29 | } 30 | 31 | // Begin describing the response message. (2.05 CONTENT, 32 | // in this case) 33 | nyoci_outbound_begin_response(COAP_RESULT_205_CONTENT); 34 | 35 | // Add an option describing the content type as plaintext. 36 | nyoci_outbound_add_option_uint( 37 | COAP_OPTION_CONTENT_TYPE, 38 | COAP_CONTENT_TYPE_TEXT_PLAIN 39 | ); 40 | 41 | // Set the content of our response to be "Hello world!". 42 | nyoci_outbound_append_content("Hello world!", NYOCI_CSTR_LEN); 43 | 44 | // Send the response we hae created, passing the return value 45 | // to our caller. 46 | return nyoci_outbound_send(); 47 | } 48 | 49 | int 50 | main(void) 51 | { 52 | nyoci_t instance; 53 | 54 | NYOCI_LIBRARY_VERSION_CHECK(); 55 | 56 | // Create our instance on the default CoAP port. If the port 57 | // is already in use, we will pick the next available port number. 58 | instance = nyoci_create(); 59 | 60 | if (!instance) { 61 | perror("Unable to create LibNyoci instance"); 62 | exit(EXIT_FAILURE); 63 | } 64 | 65 | nyoci_plat_bind_to_port(instance, NYOCI_SESSION_TYPE_UDP, COAP_DEFAULT_PORT); 66 | 67 | printf("Listening on port %d\n",nyoci_plat_get_port(instance)); 68 | 69 | // LibNyoci will always respond to requests with METHOD_NOT_IMPLEMENTED 70 | // unless a request handler is set. Unless your program is only 71 | // making CoAP requests, you'll need a line like the following 72 | // in your program. The request handler may either handle the 73 | // request itself or route the request to the appropriate handler. 74 | nyoci_set_default_request_handler(instance, &request_handler, NULL); 75 | 76 | // Loop forever. This is the most simple kind of main loop you 77 | // can haave with LibNyoci. It is appropriate for simple CoAP servers 78 | // and clients which do not need asynchronous I/O. 79 | while (1) { 80 | nyoci_plat_wait(instance, CMS_DISTANT_FUTURE); 81 | nyoci_plat_process(instance); 82 | } 83 | 84 | // We won't actually get to this line with the above loop, but it 85 | // is always a good idea to clean up when you are done. If you 86 | // provide a way to gracefully exit from your own main loop, you 87 | // can tear down the LibNyoci instance using the following command. 88 | nyoci_release(instance); 89 | 90 | return EXIT_SUCCESS; 91 | } 92 | -------------------------------------------------------------------------------- /src/examples/example-2.c: -------------------------------------------------------------------------------- 1 | /*! @page nyoci-example-2 example-2.c: Responding to a specific request 2 | ** 3 | ** This example shows how to respond to a request for a specific resource. 4 | ** 5 | ** @include example-2.c 6 | ** 7 | ** @sa @ref nyoci-instance, @ref nyoci-inbound, @ref nyoci-outbound 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | static nyoci_status_t 14 | request_handler(void* context) 15 | { 16 | /* This will respond to every GET request to `/hello-world' with 17 | ** "Hello world!". Everyone else gets a 4.04 Not Found. */ 18 | 19 | printf("Got a request!\n"); 20 | 21 | // Only handle GET requests for now. Returning NYOCI_STATUS_NOT_IMPLEMENTED 22 | // here without sending a response will cause us to automatically 23 | // send a METHOD_NOT_IMPLEMENTED response. 24 | if (nyoci_inbound_get_code() != COAP_METHOD_GET) { 25 | return NYOCI_STATUS_NOT_IMPLEMENTED; 26 | } 27 | 28 | // Skip to the URI path option 29 | while (nyoci_inbound_peek_option(NULL, NULL) != COAP_OPTION_URI_PATH) { 30 | if (nyoci_inbound_next_option(NULL, NULL) == COAP_OPTION_INVALID) { 31 | break; 32 | } 33 | } 34 | 35 | // If our URI path matches what we are looking for... 36 | if (nyoci_inbound_option_strequal(COAP_OPTION_URI_PATH, "hello-world")) { 37 | 38 | // Begin describing the response message. (2.05 CONTENT, 39 | // in this case) 40 | nyoci_outbound_begin_response(COAP_RESULT_205_CONTENT); 41 | 42 | // Add an option describing the content type as plaintext. 43 | nyoci_outbound_add_option_uint( 44 | COAP_OPTION_CONTENT_TYPE, 45 | COAP_CONTENT_TYPE_TEXT_PLAIN 46 | ); 47 | 48 | // Set the content of our response to be "Hello world!". 49 | nyoci_outbound_append_content("Hello world!", NYOCI_CSTR_LEN); 50 | 51 | // Send the response we hae created, passing the return value 52 | // to our caller. 53 | return nyoci_outbound_send(); 54 | } 55 | 56 | return NYOCI_STATUS_NOT_FOUND; 57 | } 58 | 59 | int 60 | main(void) 61 | { 62 | nyoci_t instance; 63 | 64 | NYOCI_LIBRARY_VERSION_CHECK(); 65 | 66 | // Create our instance on the default CoAP port. If the port 67 | // is already in use, we will pick the next available port number. 68 | instance = nyoci_create(); 69 | 70 | if (!instance) { 71 | perror("Unable to create LibNyoci instance"); 72 | exit(EXIT_FAILURE); 73 | } 74 | 75 | nyoci_plat_bind_to_port(instance, NYOCI_SESSION_TYPE_UDP, COAP_DEFAULT_PORT); 76 | 77 | printf("Listening on port %d\n",nyoci_plat_get_port(instance)); 78 | 79 | // LibNyoci will always respond to requests with METHOD_NOT_IMPLEMENTED 80 | // unless a request handler is set. Unless your program is only 81 | // making CoAP requests, you'll need a line like the following 82 | // in your program. The request handler may either handle the 83 | // request itself or route the request to the appropriate handler. 84 | nyoci_set_default_request_handler(instance, &request_handler, NULL); 85 | 86 | // Loop forever. This is the most simple kind of main loop you 87 | // can haave with LibNyoci. It is appropriate for simple CoAP servers 88 | // and clients which do not need asynchronous I/O. 89 | while (1) { 90 | nyoci_plat_wait(instance, CMS_DISTANT_FUTURE); 91 | nyoci_plat_process(instance); 92 | } 93 | 94 | // We won't actually get to this line with the above loop, but it 95 | // is always a good idea to clean up when you are done. If you 96 | // provide a way to gracefully exit from your own main loop, you 97 | // can tear down the LibNyoci instance using the following command. 98 | nyoci_release(instance); 99 | 100 | return EXIT_SUCCESS; 101 | } 102 | -------------------------------------------------------------------------------- /src/examples/example-3.c: -------------------------------------------------------------------------------- 1 | /*! @page nyoci-example-3 example-3.c: Using the node router 2 | ** 3 | ** This example shows how to respond to a request for specific resources 4 | ** using the node router. 5 | ** 6 | ** @include example-3.c 7 | ** 8 | ** ## Results ## 9 | ** 10 | ** $ nyocictl 11 | ** Listening on port 61617. 12 | ** coap://localhost/> ls 13 | ** hello-world 14 | ** coap://localhost/> cat hello-world 15 | ** Hello world! 16 | ** coap://localhost/> cat hello-world -i 17 | ** CoAP/1.0 2.05 CONTENT tt=ACK(2) msgid=0xCBE1 18 | ** Token: CB E1 19 | ** Content-type: text/plain;charset=utf-8 20 | ** Payload-Size: 12 21 | ** 22 | ** Hello world! 23 | ** coap://localhost/> 24 | ** 25 | ** @sa @ref nyoci-node-router 26 | ** 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | static nyoci_status_t 34 | request_handler(void* context) 35 | { 36 | printf("Got a request!\n"); 37 | 38 | // Only handle GET requests for now. 39 | if(nyoci_inbound_get_code() != COAP_METHOD_GET) { 40 | return NYOCI_STATUS_NOT_IMPLEMENTED; 41 | } 42 | 43 | // Begin describing the response. 44 | nyoci_outbound_begin_response(COAP_RESULT_205_CONTENT); 45 | 46 | nyoci_outbound_add_option_uint( 47 | COAP_OPTION_CONTENT_TYPE, 48 | COAP_CONTENT_TYPE_TEXT_PLAIN 49 | ); 50 | 51 | nyoci_outbound_append_content("Hello world!", NYOCI_CSTR_LEN); 52 | 53 | return nyoci_outbound_send(); 54 | } 55 | 56 | int 57 | main(void) 58 | { 59 | nyoci_t instance; 60 | nyoci_node_t root_node; 61 | 62 | NYOCI_LIBRARY_VERSION_CHECK(); 63 | 64 | // Create our instance on the default CoAP port. If the port 65 | // is already in use, we will pick the next available port number. 66 | instance = nyoci_create(); 67 | 68 | if (!instance) { 69 | perror("Unable to create LibNyoci instance"); 70 | exit(EXIT_FAILURE); 71 | } 72 | 73 | nyoci_plat_bind_to_port(instance, NYOCI_SESSION_TYPE_UDP, COAP_DEFAULT_PORT); 74 | 75 | // Join coap multicast groups 76 | nyoci_plat_join_standard_groups(instance, NYOCI_ANY_INTERFACE); 77 | 78 | root_node = nyoci_node_init(NULL, NULL, NULL); 79 | 80 | // LibNyoci will always respond to requests with METHOD_NOT_IMPLEMENTED 81 | // unless a request handler is set. Unless your program is only 82 | // making CoAP requests, you'll need a line like the following 83 | // in your program. The request handler may either handle the 84 | // request itself or route the request to the appropriate handler. 85 | // In this case, we are going to use the node router. 86 | nyoci_set_default_request_handler(instance, &nyoci_node_router_handler, (void*)root_node); 87 | 88 | nyoci_node_t hello_node = nyoci_node_init(NULL, root_node, "hello-world"); 89 | hello_node->request_handler = &request_handler; 90 | hello_node->context = NULL; 91 | 92 | printf("Listening on port %d\n", nyoci_plat_get_port(instance)); 93 | 94 | // Loop forever. This is the most simple kind of main loop you 95 | // can haave with LibNyoci. It is appropriate for simple CoAP servers 96 | // and clients which do not need asynchronous I/O. 97 | while (1) { 98 | nyoci_plat_wait(instance, CMS_DISTANT_FUTURE); 99 | nyoci_plat_process(instance); 100 | } 101 | 102 | // We won't actually get to this line with the above loop, but it 103 | // is always a good idea to clean up when you are done. If you 104 | // provide a way to gracefully exit from your own main loop, you 105 | // can tear down the LibNyoci instance using the following command. 106 | nyoci_release(instance); 107 | 108 | return EXIT_SUCCESS; 109 | } 110 | -------------------------------------------------------------------------------- /src/examples/example-4.c: -------------------------------------------------------------------------------- 1 | /*! @page nyoci-example-4 example-4.c: Making observable resources 2 | ** 3 | ** This example shows how to make resources observable. 4 | ** 5 | ** @include example-4.c 6 | ** 7 | ** ## Results ## 8 | ** 9 | ** $ nyocictl 10 | ** Listening on port 61617. 11 | ** coap://localhost/> ls 12 | ** hello-world 13 | ** coap://localhost/> obs -i hello-world 14 | ** CoAP/1.0 2.05 CONTENT tt=ACK(2) msgid=0x1E80 15 | ** Token: 1E 80 16 | ** Observe: 0 17 | ** Content-type: text/plain;charset=utf-8 18 | ** Payload-Size: 12 19 | ** 20 | ** Hello world! 21 | ** 22 | ** CoAP/1.0 2.05 CONTENT tt=NON(1) msgid=0x0961 23 | ** Token: 1E 80 24 | ** Observe: 1 25 | ** Content-type: text/plain;charset=utf-8 26 | ** Payload-Size: 12 27 | ** 28 | ** Hello world! 29 | ** 30 | ** CoAP/1.0 2.05 CONTENT tt=NON(1) msgid=0x0A61 31 | ** Token: 1E 80 32 | ** Observe: 2 33 | ** Content-type: text/plain;charset=utf-8 34 | ** Payload-Size: 12 35 | ** 36 | ** Hello world! 37 | ** 38 | ** ^Ccoap://localhost/> 39 | ** 40 | ** 41 | ** @sa @ref nyoci-observable 42 | */ 43 | 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | 50 | #define ARBITRARY_OBSERVABLE_KEY 23 51 | #define TRIGGER_FREQUENCY 5 // In Seconds 52 | 53 | static nyoci_status_t 54 | request_handler(void* context) 55 | { 56 | nyoci_observable_t observable = context; 57 | 58 | if (!nyoci_inbound_is_fake()) { 59 | printf("Got a request!\n"); 60 | } 61 | 62 | // Only handle GET requests for now. 63 | if (nyoci_inbound_get_code() != COAP_METHOD_GET) { 64 | return NYOCI_STATUS_NOT_IMPLEMENTED; 65 | } 66 | 67 | // Begin describing the response. 68 | nyoci_outbound_begin_response(COAP_RESULT_205_CONTENT); 69 | 70 | // This is the key line to making a resource observable. 71 | // It must be placed after nyoci_outbound_begin_response() 72 | // and before nyoci_outbound_send(). When this resource changes, 73 | // a simple call to nyoci_observable_trigger() with the given 74 | // nyoci_observable object and observable key will trigger the 75 | // observers to be updated. Really --- that's it...! 76 | nyoci_observable_update(observable, ARBITRARY_OBSERVABLE_KEY); 77 | 78 | nyoci_outbound_add_option_uint( 79 | COAP_OPTION_CONTENT_TYPE, 80 | COAP_CONTENT_TYPE_TEXT_PLAIN 81 | ); 82 | 83 | nyoci_outbound_append_content("Hello world!", NYOCI_CSTR_LEN); 84 | 85 | return nyoci_outbound_send(); 86 | } 87 | 88 | int 89 | main(void) 90 | { 91 | nyoci_t instance; 92 | nyoci_node_t root_node; 93 | struct nyoci_observable_s observable = { 0 }; 94 | time_t next_trigger; 95 | 96 | NYOCI_LIBRARY_VERSION_CHECK(); 97 | 98 | instance = nyoci_create(); 99 | 100 | if (!instance) { 101 | perror("Unable to create LibNyoci instance"); 102 | exit(EXIT_FAILURE); 103 | } 104 | 105 | nyoci_plat_bind_to_port(instance, NYOCI_SESSION_TYPE_UDP, COAP_DEFAULT_PORT); 106 | 107 | root_node = nyoci_node_init(NULL, NULL, NULL); 108 | 109 | next_trigger = time(NULL) + TRIGGER_FREQUENCY; 110 | 111 | nyoci_set_default_request_handler( 112 | instance, 113 | &nyoci_node_router_handler, 114 | (void*)root_node 115 | ); 116 | 117 | nyoci_node_t hello_node = nyoci_node_init(NULL,root_node,"hello-world"); 118 | hello_node->request_handler = &request_handler; 119 | hello_node->context = &observable; 120 | 121 | printf("Listening on port %d\n", nyoci_plat_get_port(instance)); 122 | 123 | while (1) { 124 | nyoci_plat_wait(instance, (next_trigger - time(NULL)) * MSEC_PER_SEC); 125 | nyoci_plat_process(instance); 126 | 127 | // Occasionally trigger this resource as having changed. 128 | if ((next_trigger - time(NULL))<=0) { 129 | printf("%d observers registered\n", nyoci_observable_observer_count(&observable, ARBITRARY_OBSERVABLE_KEY)); 130 | nyoci_observable_trigger(&observable, ARBITRARY_OBSERVABLE_KEY ,0); 131 | next_trigger = time(NULL) + TRIGGER_FREQUENCY; 132 | } 133 | } 134 | 135 | nyoci_release(instance); 136 | 137 | return EXIT_SUCCESS; 138 | } 139 | -------------------------------------------------------------------------------- /src/libnyoci/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AUTOMAKE_OPTIONS = subdir-objects 3 | @CODE_COVERAGE_RULES@ 4 | 5 | lib_LTLIBRARIES = libnyoci.la 6 | 7 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 8 | AM_CFLAGS = $(CFLAGS) $(CODE_COVERAGE_CFLAGS) 9 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) 10 | 11 | pkgconfigdir = ${prefix}/lib/pkgconfig 12 | pkgconfig_DATA = libnyoci.pc 13 | 14 | libnyoci_la_SOURCES = \ 15 | nyoci.c \ 16 | nyoci-timer.c \ 17 | coap.c coap.h \ 18 | nyoci-outbound.c \ 19 | nyoci-inbound.c \ 20 | nyoci-observable.c \ 21 | nyoci-transaction.c \ 22 | nyoci-dupe.c \ 23 | nyoci-missing.c \ 24 | nyoci-session.c \ 25 | nyoci-async.c \ 26 | $(NULL) 27 | 28 | libnyoci_la_SOURCES += \ 29 | nyoci-helpers.h \ 30 | nyoci-internal.h \ 31 | nyoci-logging.h \ 32 | nyoci-dupe.h \ 33 | nyoci-missing.h \ 34 | nyoci-async.h \ 35 | nyoci-defaults.h \ 36 | nyoci-status.h \ 37 | $(NULL) 38 | 39 | libnyoci_la_SOURCES += \ 40 | btree.c btree.h \ 41 | ll.h \ 42 | url-helpers.c \ 43 | fasthash.c \ 44 | string-utils.c \ 45 | url-helpers.h \ 46 | fasthash.h \ 47 | string-utils.h \ 48 | assert-macros.h \ 49 | $(NULL) 50 | 51 | pkginclude_HEADERS = \ 52 | libnyoci.h \ 53 | nyoci-opts.h \ 54 | nyoci-defaults.h \ 55 | nyoci-timer.h \ 56 | nyoci-transaction.h \ 57 | nyoci-observable.h \ 58 | nyoci-helpers.h \ 59 | nyoci-session.h \ 60 | nyoci-status.h \ 61 | nyoci-async.h \ 62 | nyoci-plat-net-func.h \ 63 | nyoci-plat-tls-func.h \ 64 | $(top_builddir)/src/libnyoci/nyoci-config.h \ 65 | btree.h \ 66 | coap.h \ 67 | ll.h \ 68 | $(NULL) 69 | 70 | # Eventually these headers should be removed or reconsidered, 71 | # but at the moment is is rather convenient to keep them around. 72 | pkginclude_HEADERS += \ 73 | assert-macros.h \ 74 | fasthash.h \ 75 | url-helpers.h \ 76 | string-utils.h \ 77 | nyoci-internal.h \ 78 | nyoci-dupe.h \ 79 | nyoci-logging.h \ 80 | $(NULL) 81 | 82 | EXTRA_DIST = nyoci-config.h.in 83 | 84 | libnyoci_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) $(HIDDEN_VISIBILITY_CFLAGS) 85 | libnyoci_la_LIBADD = $(ALLOCA) $(PTHREAD_LIBS) ../plat-net/${NYOCI_PLAT_NET}/libnyoci-plat-net.la $(MISSING_LIBADD) 86 | libnyoci_la_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCLUDES) $(MISSING_CPPFLAGS) 87 | libnyoci_la_LDFLAGS = $(AM_LDFLAGS) $(OPENSSL_LDFLAGS) 88 | 89 | if NYOCI_PLAT_TLS 90 | #libnyoci_la_LIBADD += $(OPENSSL_LIBS) 91 | libnyoci_la_LIBADD += ../plat-tls/${NYOCI_PLAT_TLS}/libnyoci-plat-tls.la 92 | endif 93 | 94 | check_PROGRAMS = btreetest 95 | btreetest_SOURCES = btree.c 96 | btreetest_CFLAGS = $(AM_CFLAGS) -DBTREE_SELF_TEST=1 97 | 98 | DISTCLEANFILES = .deps Makefile 99 | 100 | TESTS = btreetest 101 | -------------------------------------------------------------------------------- /src/libnyoci/assert-macros.h: -------------------------------------------------------------------------------- 1 | /*! @file assert-macros.h 2 | ** @author Robert Quattlebaum 3 | ** @brief "Assert" and "Require" macros 4 | ** 5 | ** Originally published 2010-8-31. 6 | ** 7 | ** This file was written by Robert Quattlebaum . 8 | ** 9 | ** This work is provided as-is. Unless otherwise provided in writing, 10 | ** Robert Quattlebaum makes no representations or warranties of any 11 | ** kind concerning this work, express, implied, statutory or otherwise, 12 | ** including without limitation warranties of title, merchantability, 13 | ** fitness for a particular purpose, non infringement, or the absence 14 | ** of latent or other defects, accuracy, or the present or absence of 15 | ** errors, whether or not discoverable, all to the greatest extent 16 | ** permissible under applicable law. 17 | ** 18 | ** To the extent possible under law, Robert Quattlebaum has waived all 19 | ** copyright and related or neighboring rights to this work. This work 20 | ** is published from the United States. 21 | ** 22 | ** I, Robert Quattlebaum, dedicate any and all copyright interest in 23 | ** this work to the public domain. I make this dedication for the 24 | ** benefit of the public at large and to the detriment of my heirs and 25 | ** successors. I intend this dedication to be an overt act of 26 | ** relinquishment in perpetuity of all present and future rights to 27 | ** this code under copyright law. In jurisdictions where this is not 28 | ** possible, I hereby release this code under the Creative Commons 29 | ** Zero (CC0) license. 30 | ** 31 | ** * 32 | ** 33 | ** ------------------------------------------------------------------- 34 | ** 35 | ** See 36 | ** for an explanation about how to use these macros and justification 37 | ** for using this pattern in general. 38 | */ 39 | 40 | #ifndef __DARC_ASSERT_MACROS__ 41 | #define __DARC_ASSERT_MACROS__ 42 | 43 | #if CONTIKI 44 | #define assert_error_stream stdout 45 | #else 46 | #define assert_error_stream stderr 47 | #endif 48 | 49 | #if !DEBUG && !defined(NDEBUG) 50 | #define NDEBUG 1 51 | #endif 52 | 53 | #if ASSERT_MACROS_USE_SYSLOG 54 | #include 55 | #endif 56 | 57 | #if HAVE_ASSERTMACROS_H 58 | #include 59 | #else 60 | #include 61 | #include 62 | #if !DEBUG || ASSERT_MACROS_SQUELCH 63 | #define assert_printf(fmt, ...) do { } while(0) 64 | #define check_string(c, s) do { } while(0) 65 | #define require_action_string(c, l, a, s) \ 66 | do { if(!(c)) { \ 67 | a; goto l; \ 68 | } \ 69 | } while(0) 70 | #define require_noerr_action_string(c, l, a, s) \ 71 | do { if((c)!=0) { \ 72 | a; goto l; \ 73 | } \ 74 | } while(0) 75 | #else 76 | #if __AVR__ 77 | #define assert_printf(fmt, ...) \ 78 | fprintf_P(assert_error_stream, \ 79 | PSTR(__FILE__ ":%d: "fmt"\n"), \ 80 | __LINE__, \ 81 | __VA_ARGS__) 82 | #else 83 | #if ASSERT_MACROS_USE_SYSLOG 84 | #define assert_printf(fmt, ...) \ 85 | syslog(LOG_NOTICE, \ 86 | __FILE__ ":%d: "fmt"\n", \ 87 | __LINE__, \ 88 | __VA_ARGS__) 89 | #elif ASSERT_MACROS_USE_VANILLA_PRINTF 90 | #define assert_printf(fmt, ...) \ 91 | printf(__FILE__ ":%d: "fmt"\n", \ 92 | __LINE__, \ 93 | __VA_ARGS__) 94 | #else 95 | #define assert_printf(fmt, ...) \ 96 | fprintf(assert_error_stream, \ 97 | __FILE__ ":%d: "fmt"\n", \ 98 | __LINE__, \ 99 | __VA_ARGS__) 100 | #endif 101 | #endif 102 | #define check_string(c, s) \ 103 | do { if(!(c)) assert_printf("Check Failed (%s)", \ 104 | s); } while(0) 105 | #define require_action_string(c, l, a, s) \ 106 | do { if(!(c)) { \ 107 | assert_printf("Requirement Failed (%s)", \ 108 | s); a; goto l; \ 109 | } \ 110 | } while(0) 111 | #define require_noerr_action_string(c, l, a, s) \ 112 | do { \ 113 | int err = (int)(c); \ 114 | if(err!=0) { \ 115 | int errnobackup = errno; \ 116 | assert_printf("Requirement Failed, error %d (%s)", err, s); \ 117 | errno = errnobackup; \ 118 | a; \ 119 | goto l; \ 120 | } \ 121 | } while(0) 122 | #endif 123 | 124 | #define check(c) check_string(c, # c) 125 | #define check_noerr(c) check((c) == 0) 126 | #define check_noerr_string(c, s) check_string((c) == 0, s) 127 | #define require_quiet(c, l) do { if(!(c)) goto l; } while(0) 128 | #define require(c, l) require_action_string(c, l, {}, # c) 129 | 130 | #define require_noerr(c, l) require_noerr_action_string(c, l, {}, # c) 131 | #define require_noerr_action(c, l, a) require_noerr_action_string(c, l, a, # c) 132 | #define require_action(c, l, a) require_action_string(c, l, a, # c) 133 | #define require_string(c, l, s) \ 134 | require_action_string(c, l, \ 135 | do {} while(0), s) 136 | #endif 137 | 138 | #if OVERRIDE_ASSERT_H 139 | #undef assert 140 | #undef __assert 141 | #define assert(e) \ 142 | ((void) ((e) ? 0 : __assert (#e, __FILE__, __LINE__))) 143 | #define __assert(e, file, line) \ 144 | ((void)assert_printf ("%s:%u: failed assertion `%s'", file, line, e), abort()) 145 | #endif // OVERRIDE_ASSERT_H 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /src/libnyoci/btree.h: -------------------------------------------------------------------------------- 1 | /*! @file btree.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Binary Tree Functions 4 | ** 5 | ** Originally published 2010-8-31. 6 | ** 7 | ** This file was written by Robert Quattlebaum . 8 | ** 9 | ** This work is provided as-is. Unless otherwise provided in writing, 10 | ** Robert Quattlebaum makes no representations or warranties of any 11 | ** kind concerning this work, express, implied, statutory or otherwise, 12 | ** including without limitation warranties of title, merchantability, 13 | ** fitness for a particular purpose, non infringement, or the absence 14 | ** of latent or other defects, accuracy, or the present or absence of 15 | ** errors, whether or not discoverable, all to the greatest extent 16 | ** permissible under applicable law. 17 | ** 18 | ** To the extent possible under law, Robert Quattlebaum has waived all 19 | ** copyright and related or neighboring rights to this work. This work 20 | ** is published from the United States. 21 | ** 22 | ** I, Robert Quattlebaum, dedicate any and all copyright interest in 23 | ** this work to the public domain. I make this dedication for the 24 | ** benefit of the public at large and to the detriment of my heirs and 25 | ** successors. I intend this dedication to be an overt act of 26 | ** relinquishment in perpetuity of all present and future rights to 27 | ** this code under copyright law. In jurisdictions where this is not 28 | ** possible, I hereby release this code under the Creative Commons 29 | ** Zero (CC0) license. 30 | ** 31 | ** * 32 | */ 33 | 34 | #ifndef __BTREE_HEADER__ 35 | #define __BTREE_HEADER__ 1 36 | 37 | #include 38 | #include 39 | #include // For ssize_t 40 | 41 | #if defined(__cplusplus) 42 | extern "C" { 43 | #endif 44 | 45 | /*! @defgroup btree Binary Tree Functions 46 | ** @{ 47 | */ 48 | 49 | 50 | struct bt_item_s; 51 | 52 | typedef struct bt_item_s *bt_item_t; 53 | 54 | struct bt_item_s { 55 | bt_item_t lhs; 56 | bt_item_t rhs; 57 | bt_item_t parent; 58 | }; 59 | 60 | typedef signed char bt_compare_result_t; 61 | 62 | typedef bt_compare_result_t (*bt_compare_func_t)(const void* lhs, 63 | const void* rhs, void* context); 64 | 65 | typedef void (*bt_delete_func_t)(void* item, void* context); 66 | 67 | //! Inserts the given item into the tree. 68 | NYOCI_INTERNAL_EXTERN int bt_insert( 69 | void** bt, //!< Pointer to the root of the tree 70 | void* item, //!< Item to insert 71 | bt_compare_func_t compare_func, //!< Comparison function 72 | bt_delete_func_t delete_func, //!< Deletion function, used if comparison is equal 73 | void* context //!< Context, passed into comparison and deletion callbacks. 74 | ); 75 | 76 | //! Finds and returns a node matching the given criteria. 77 | NYOCI_INTERNAL_EXTERN void* bt_find( 78 | void*const* bt, 79 | const void* item, 80 | bt_compare_func_t compare_func, 81 | void* context 82 | ); 83 | 84 | //! Removes the given item from the tree, if present. 85 | NYOCI_INTERNAL_EXTERN bool bt_remove( 86 | void** bt, 87 | void* item, 88 | bt_compare_func_t compare_func, 89 | bt_delete_func_t delete_func, 90 | void* context 91 | ); 92 | 93 | //! Finds the left-most node in the subtree described by item. 94 | NYOCI_INTERNAL_EXTERN void* bt_first(void* item); 95 | 96 | //! Finds the right-most node in the subtree described by item. 97 | NYOCI_INTERNAL_EXTERN void* bt_last(void* item); 98 | 99 | //! Returns the next node in the tree, or NULL the given item is the last (right-most) node in the tree. 100 | //! Performs an in-order depth-first traversal. 101 | NYOCI_INTERNAL_EXTERN void* bt_next(void* item); 102 | 103 | //! Returns the previous node in the tree, or NULL the given item is the first (left-most) node in the tree. 104 | //! Performs a reverse-order depth-first traversal. 105 | NYOCI_INTERNAL_EXTERN void* bt_prev(void* item); 106 | 107 | //! Traverses the given tree to determine the number of nodes it contains. 108 | NYOCI_INTERNAL_EXTERN int bt_count(void*const* bt); 109 | 110 | NYOCI_INTERNAL_EXTERN int bt_get_balance(void* node); 111 | 112 | NYOCI_INTERNAL_EXTERN void bt_rotate_left(void** pivot); 113 | 114 | NYOCI_INTERNAL_EXTERN void bt_rotate_right(void** pivot); 115 | 116 | //! Completely rebalance of the tree. 117 | NYOCI_INTERNAL_EXTERN unsigned int bt_rebalance(void** bt); 118 | 119 | //! Completely unbalances the tree. Primarily useful for debugging. 120 | NYOCI_INTERNAL_EXTERN unsigned int bt_unbalance(void** bt); 121 | 122 | //! Splays the tree to a new root. Useful for splay trees. 123 | NYOCI_INTERNAL_EXTERN unsigned int bt_splay(void** bt, void* root); 124 | 125 | #if defined(__cplusplus) 126 | } 127 | #endif 128 | 129 | /*! @} */ 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /src/libnyoci/fasthash.c: -------------------------------------------------------------------------------- 1 | // 2 | // fasthash.c 3 | // LibNyoci 4 | // 5 | // Created by Robert Quattlebaum on 12/23/12. 6 | // Copyright (c) 2012 deepdarc. All rights reserved. 7 | // 8 | 9 | #if HAVE_CONFIG_H 10 | #include 11 | #endif 12 | 13 | #include "libnyoci.h" 14 | 15 | #include "fasthash.h" 16 | #include 17 | #include 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | // MARK: - 21 | // MARK: Fasthash 22 | 23 | static void 24 | fasthash_feed_block(struct fasthash_state_s* state, uint32_t blk) { 25 | // XOR the block count into the block. 26 | blk ^= (state->bytes >> 2); 27 | 28 | // XOR the previous result into the hash state. 29 | state->hash ^= blk; 30 | 31 | // Mix up the hash state using a linear congruential generator. 32 | state->hash = state->hash * 1664525 + 1013904223; 33 | } 34 | 35 | void 36 | fasthash_start(struct fasthash_state_s* state, uint32_t salt) { 37 | memset((void*)state, 0, sizeof(*state)); 38 | // Feed in the salt first. 39 | fasthash_feed_block(state, salt); 40 | } 41 | 42 | void 43 | fasthash_feed_byte(struct fasthash_state_s* state, uint8_t data) { 44 | state->next |= (data << (8 * (state->bytes++ & 3))); 45 | if ((state->bytes & 3) == 0) { 46 | fasthash_feed_block(state, state->next); 47 | state->next = 0; 48 | } 49 | } 50 | 51 | void 52 | fasthash_feed(struct fasthash_state_s* state, const uint8_t* data, uint8_t len) { 53 | while (len--) { 54 | fasthash_feed_byte(state, *data++); 55 | } 56 | } 57 | 58 | fasthash_hash_t 59 | fasthash_finish(struct fasthash_state_s* state) { 60 | if (state->bytes & 3) { 61 | fasthash_feed_block(state, state->next); 62 | state->bytes = 0; 63 | } 64 | 65 | // One last shuffle 66 | fasthash_feed_block(state, 1103515245); 67 | 68 | return state->hash; 69 | } 70 | 71 | uint32_t 72 | fasthash_finish_uint32(struct fasthash_state_s* state) { 73 | return fasthash_finish(state) >> 0; 74 | } 75 | 76 | uint16_t 77 | fasthash_finish_uint16(struct fasthash_state_s* state) { 78 | return fasthash_finish_uint32(state)>>16; 79 | } 80 | 81 | uint8_t 82 | fasthash_finish_uint8(struct fasthash_state_s* state) { 83 | return fasthash_finish_uint32(state)>>24; 84 | } 85 | -------------------------------------------------------------------------------- /src/libnyoci/fasthash.h: -------------------------------------------------------------------------------- 1 | /* @file fasthash.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_fasthash_h 30 | #define NYOCI_fasthash_h 31 | 32 | #include 33 | 34 | typedef uint32_t fasthash_hash_t; 35 | 36 | struct fasthash_state_s { 37 | fasthash_hash_t hash; 38 | uint32_t bytes; 39 | fasthash_hash_t next; 40 | }; 41 | 42 | NYOCI_INTERNAL_EXTERN void fasthash_start(struct fasthash_state_s* state, fasthash_hash_t salt); 43 | NYOCI_INTERNAL_EXTERN void fasthash_feed_byte(struct fasthash_state_s* state, uint8_t data); 44 | NYOCI_INTERNAL_EXTERN void fasthash_feed(struct fasthash_state_s* state, const uint8_t* data, uint8_t len); 45 | NYOCI_INTERNAL_EXTERN fasthash_hash_t fasthash_finish(struct fasthash_state_s* state); 46 | NYOCI_INTERNAL_EXTERN uint32_t fasthash_finish_uint32(struct fasthash_state_s* state); 47 | NYOCI_INTERNAL_EXTERN uint16_t fasthash_finish_uint16(struct fasthash_state_s* state); 48 | NYOCI_INTERNAL_EXTERN uint8_t fasthash_finish_uint8(struct fasthash_state_s* state); 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/libnyoci/libnyoci.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: LibNyoci 7 | Description: Not Your Ordinary CoAP Implementation 8 | URL: http://libnyoci.org/ 9 | Version: @VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lnyoci 12 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-async.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-async.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Asynchronous Response Support 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef NYOCI_nyoci_async_h 31 | #define NYOCI_nyoci_async_h 32 | 33 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 34 | #error "Do not include this header directly, include instead" 35 | #endif 36 | 37 | NYOCI_BEGIN_C_DECLS 38 | 39 | /*! @addtogroup nyoci 40 | ** @{ 41 | */ 42 | 43 | /*! @defgroup nyoci_async Asynchronous response support API 44 | ** @{ 45 | */ 46 | 47 | //! Don't immediately send an empty coap message. 48 | /*! Normally, when you call nyoci_outbound_begin_async_response(), 49 | ** an empty message is sent to the requester to indicate 50 | ** that they don't need to send any retries. This flag 51 | ** tells the function to not attempt to send this empty message. 52 | */ 53 | #define NYOCI_ASYNC_RESPONSE_FLAG_DONT_ACK (1<<0) 54 | 55 | struct nyoci_async_response_s { 56 | nyoci_sockaddr_t sockaddr_local; 57 | nyoci_sockaddr_t sockaddr_remote; 58 | 59 | coap_size_t request_len; 60 | union { 61 | struct coap_header_s header; 62 | uint8_t bytes[NYOCI_ASYNC_RESPONSE_MAX_LENGTH]; 63 | } request; 64 | }; 65 | 66 | typedef struct nyoci_async_response_s* nyoci_async_response_t; 67 | 68 | NYOCI_API_EXTERN bool nyoci_inbound_is_related_to_async_response(struct nyoci_async_response_s* x); 69 | 70 | NYOCI_API_EXTERN nyoci_status_t nyoci_start_async_response(struct nyoci_async_response_s* x,int flags); 71 | 72 | NYOCI_API_EXTERN nyoci_status_t nyoci_finish_async_response(struct nyoci_async_response_s* x); 73 | 74 | NYOCI_API_EXTERN nyoci_status_t nyoci_outbound_begin_async_response(coap_code_t code, struct nyoci_async_response_s* x); 75 | 76 | /*! @} */ 77 | 78 | 79 | /*! @} */ 80 | 81 | NYOCI_END_C_DECLS 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-config.h.in: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-config.h 2 | ** @author Robert Quattlebaum 3 | ** @brief LibNyoci Build Options 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #undef NYOCI_EMBEDDED 31 | 32 | #undef NYOCI_SINGLETON 33 | 34 | #undef NYOCI_PLAT_NET_POSIX_FAMILY 35 | 36 | #undef NYOCI_PLAT_NET 37 | 38 | #undef NYOCI_PLAT_TLS 39 | 40 | #undef NYOCI_AVOID_MALLOC 41 | 42 | #undef NYOCI_AVOID_PRINTF 43 | 44 | #undef NYOCI_DEFAULT_PORT 45 | 46 | #undef NYOCI_CONF_DUPE_BUFFER_SIZE 47 | 48 | #undef NYOCI_CONF_ENABLE_VHOSTS 49 | 50 | #undef NYOCI_CONF_MAX_ALLOCED_NODES 51 | 52 | #undef NYOCI_CONF_MAX_GROUPS 53 | 54 | #undef NYOCI_CONF_MAX_OBSERVERS 55 | 56 | #undef NYOCI_CONF_MAX_PAIRINGS 57 | 58 | #undef NYOCI_CONF_MAX_TIMEOUT 59 | 60 | #undef NYOCI_CONF_NODE_ROUTER 61 | 62 | #undef NYOCI_CONF_TRANS_ENABLE_BLOCK2 63 | 64 | #undef NYOCI_CONF_TRANS_ENABLE_OBSERVING 65 | 66 | #undef NYOCI_CONF_USE_DNS 67 | 68 | #undef NYOCI_ADD_NEWLINES_TO_LIST_OUTPUT 69 | 70 | #undef NYOCI_ASYNC_RESPONSE_MAX_LENGTH 71 | 72 | #undef NYOCI_DEBUG_INBOUND_DROP_PERCENT 73 | 74 | #undef NYOCI_DEBUG_OUTBOUND_DROP_PERCENT 75 | 76 | #undef NYOCI_MAX_CASCADE_COUNT 77 | 78 | #undef NYOCI_MAX_CONTENT_LENGTH 79 | 80 | #undef NYOCI_MAX_OBSERVERS 81 | 82 | #undef NYOCI_MAX_PACKET_LENGTH 83 | 84 | #undef NYOCI_MAX_PATH_LENGTH 85 | 86 | #undef NYOCI_MAX_URI_LENGTH 87 | 88 | #undef NYOCI_MAX_VHOSTS 89 | 90 | #undef NYOCI_TRANSACTION_BURST_COUNT 91 | 92 | #undef NYOCI_TRANSACTION_BURST_TIMEOUT_MAX 93 | 94 | #undef NYOCI_TRANSACTION_BURST_TIMEOUT_MIN 95 | 96 | #undef NYOCI_THREAD_SAFE 97 | 98 | #undef NYOCI_NODE_ROUTER_USE_BTREE 99 | 100 | #undef NYOCI_OBSERVATION_DEFAULT_MAX_AGE 101 | 102 | #undef NYOCI_OBSERVATION_KEEPALIVE_INTERVAL 103 | 104 | #undef NYOCI_OBSERVER_CON_EVENT_EXPIRATION 105 | 106 | #undef NYOCI_OBSERVER_NON_EVENT_EXPIRATION 107 | 108 | #undef NYOCI_TRANSACTIONS_USE_BTREE 109 | 110 | #undef NYOCI_TRANSACTION_BURST_COUNT 111 | 112 | #undef NYOCI_TRANSACTION_POOL_SIZE 113 | 114 | #undef NYOCI_USE_CASCADE_COUNT 115 | 116 | #undef NYOCI_VARIABLE_MAX_KEY_LENGTH 117 | 118 | #undef NYOCI_VARIABLE_MAX_VALUE_LENGTH 119 | 120 | #undef NYOCI_INTERNAL_EXTERN 121 | 122 | #undef NYOCI_API_EXTERN 123 | 124 | #undef NYOCI_DEPRECATED 125 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-dupe.c: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-dupe.c 2 | ** @author Robert Quattlebaum 3 | ** @brief Duplicate packet detection 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #if HAVE_CONFIG_H 31 | #include 32 | #endif 33 | 34 | #include 35 | #include "nyoci-internal.h" 36 | #include "nyoci-dupe.h" 37 | #include "fasthash.h" 38 | 39 | // TODO: This code could use some optimization. 40 | 41 | bool 42 | nyoci_inbound_dupe_check(void) 43 | { 44 | nyoci_t const self = nyoci_get_current_instance(); 45 | bool is_dupe = false; 46 | struct fasthash_state_s fasthash; 47 | uint32_t hash; 48 | const nyoci_sockaddr_t* const remote_sockaddr = nyoci_plat_get_remote_sockaddr(); 49 | 50 | // Calculate the message-id hash (address+port+message_id) 51 | fasthash_start(&fasthash, 0); // SECURITY-TODO: Use some sort of seed key 52 | fasthash_feed(&fasthash, (const void*)remote_sockaddr, sizeof(nyoci_sockaddr_t)); 53 | fasthash_feed(&fasthash, (const uint8_t*)&self->inbound.packet->msg_id, sizeof(self->inbound.packet->msg_id)); 54 | hash = fasthash_finish_uint32(&fasthash); 55 | 56 | // Check to see if this packet is a duplicate. 57 | unsigned int i = NYOCI_CONF_DUPE_BUFFER_SIZE; 58 | while (i--) { 59 | if (self->dupe_info.dupe[i].hash == hash) { 60 | if ((0 == memcmp(&self->dupe_info.dupe[i].from, (const void*)remote_sockaddr, sizeof(nyoci_sockaddr_t))) 61 | && (self->dupe_info.dupe[i].msg_id == self->inbound.packet->msg_id) 62 | ) { 63 | is_dupe = true; 64 | break; 65 | } 66 | } 67 | } 68 | 69 | if (!is_dupe) { 70 | // This is not a dupe, add it to the list. 71 | self->dupe_info.dupe[self->dupe_info.dupe_index].hash = hash; 72 | self->dupe_info.dupe[self->dupe_info.dupe_index].msg_id = self->inbound.packet->msg_id; 73 | memcpy(&self->dupe_info.dupe[self->dupe_info.dupe_index].from, (const void*)remote_sockaddr, sizeof(nyoci_sockaddr_t)); 74 | self->dupe_info.dupe_index++; 75 | self->dupe_info.dupe_index %= NYOCI_CONF_DUPE_BUFFER_SIZE; 76 | } 77 | 78 | return is_dupe; 79 | } 80 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-dupe.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-dupe.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Duplicate packet detection 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef NYOCI_nyoci_dupe_h 31 | #define NYOCI_nyoci_dupe_h 32 | 33 | #include "libnyoci.h" 34 | 35 | NYOCI_BEGIN_C_DECLS 36 | 37 | struct nyoci_dupe_info_s { 38 | struct { 39 | uint32_t hash; 40 | nyoci_sockaddr_t from; 41 | coap_msg_id_t msg_id; 42 | coap_code_t code; 43 | } dupe[NYOCI_CONF_DUPE_BUFFER_SIZE]; 44 | 45 | #if NYOCI_CONF_DUPE_BUFFER_SIZE<=256 46 | uint8_t dupe_index; 47 | #else 48 | uint16_t dupe_index; 49 | #endif 50 | }; 51 | 52 | bool nyoci_inbound_dupe_check(void); 53 | 54 | NYOCI_END_C_DECLS 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-helpers.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-helpers.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | 30 | #ifndef __NYOCI_HELPERS_HEADER__ 31 | #define __NYOCI_HELPERS_HEADER__ 1 32 | 33 | #include 34 | 35 | #if !defined(__SDCC) && defined(SDCC) 36 | #define __SDCC SDCC 37 | #endif 38 | 39 | #if defined(__SDCC) 40 | #include 41 | #endif 42 | 43 | #include 44 | #include 45 | 46 | #if !defined(NYOCI_BEGIN_C_DECLS) || !defined(NYOCI_END_C_DECLS) 47 | #if defined(__cplusplus) 48 | #define NYOCI_BEGIN_C_DECLS extern "C" { 49 | #define NYOCI_END_C_DECLS } 50 | #else 51 | #define NYOCI_BEGIN_C_DECLS 52 | #define NYOCI_END_C_DECLS 53 | #endif 54 | #endif 55 | 56 | ///////////////////////////////////////////////////////////////////////////// 57 | 58 | #if !defined(NYOCI_DEPRECATED) && HAVE_FUNC_ATTRIBUTE_DEPRECATED 59 | #define NYOCI_DEPRECATED __attribute__ ((deprecated)) 60 | #endif 61 | 62 | #if !defined(NYOCI_PURE_FUNC) && HAVE_FUNC_ATTRIBUTE_PURE 63 | #define NYOCI_PURE_FUNC __attribute__((pure)) 64 | #endif 65 | 66 | #if !defined(NYOCI_NON_RECURSIVE) && NYOCI_EMBEDDED && NYOCI_SINGLETON 67 | #define NYOCI_NON_RECURSIVE static 68 | #endif 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | 72 | #ifndef NYOCI_API_EXTERN 73 | #define NYOCI_API_EXTERN extern 74 | #endif 75 | 76 | #ifndef NYOCI_INTERNAL_EXTERN 77 | #define NYOCI_INTERNAL_EXTERN extern 78 | #endif 79 | 80 | #ifndef NYOCI_DEPRECATED 81 | #define NYOCI_DEPRECATED 82 | #endif 83 | 84 | #ifndef NYOCI_PURE_FUNC 85 | #define NYOCI_PURE_FUNC 86 | #endif 87 | 88 | #ifndef NYOCI_NON_RECURSIVE 89 | #define NYOCI_NON_RECURSIVE 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-logging.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-logging.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Logging support 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef __NYOCI_LOGGING_HEADER__ 31 | #define __NYOCI_LOGGING_HEADER__ 1 32 | 33 | #include "assert-macros.h" 34 | 35 | #if !VERBOSE_DEBUG 36 | 37 | #define CSTR(x) (x) 38 | 39 | #ifndef DEBUG_PRINTF 40 | #define DEBUG_PRINTF(...) do { } while(0) 41 | #endif 42 | #define NYOCI_DEBUG_OUT_FILE stdout 43 | 44 | #elif defined(__AVR__) 45 | #define NYOCI_DEBUG_OUT_FILE stdout 46 | 47 | #include 48 | #include 49 | #define CSTR(x) PSTR(x) 50 | #define DEBUG_PRINTF(...) \ 51 | do { fprintf_P(NYOCI_DEBUG_OUT_FILE, __VA_ARGS__); fputc( \ 52 | '\n', \ 53 | NYOCI_DEBUG_OUT_FILE); } while(0) 54 | 55 | #else // __AVR__ 56 | #define NYOCI_DEBUG_OUT_FILE stderr 57 | 58 | #include 59 | #define CSTR(x) (x) 60 | #if ASSERT_MACROS_USES_SYSLOG 61 | #include 62 | #define DEBUG_PRINTF(...) syslog(7, __VA_ARGS__) 63 | #elif ASSERT_MACROS_USE_VANILLA_PRINTF 64 | #define DEBUG_PRINTF(...) \ 65 | do { printf(__VA_ARGS__); printf("\n"); } while(0) 66 | #else 67 | #define DEBUG_PRINTF(...) \ 68 | do { fprintf(NYOCI_DEBUG_OUT_FILE, __VA_ARGS__); fputc('\n', \ 69 | NYOCI_DEBUG_OUT_FILE); } while(0) 70 | #endif 71 | 72 | #endif 73 | 74 | #endif // __NYOCI_LOGGING_HEADER__ 75 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-missing.c: -------------------------------------------------------------------------------- 1 | /*! @file nyoci_missing.c 2 | ** @author Robert Quattlebaum 3 | ** @brief Replacements for missing system functions 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #if HAVE_CONFIG_H 31 | #include 32 | #endif 33 | 34 | #include "nyoci-missing.h" 35 | 36 | #include 37 | 38 | #include "nyoci-helpers.h" 39 | 40 | const char gMissing; 41 | 42 | #if !NYOCI_AVOID_MALLOC 43 | #if !HAVE_STRDUP 44 | char* 45 | ___nyoci_strdup(const char* cstr) { 46 | size_t len = strlen(cstr); 47 | char* ret = (char*)malloc(len+1); 48 | memcpy(ret,cstr,len); 49 | ret[len]=0; 50 | return ret; 51 | } 52 | #endif 53 | 54 | #if !HAVE_STRNDUP 55 | char* 56 | ___nyoci_strndup(const char* cstr,size_t maxlen) { 57 | size_t len = strlen(cstr); 58 | char* ret; 59 | if(maxlen 3 | ** @brief Replacements for missing system functions 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef NYOCI_nyoci_missing_h 31 | #define NYOCI_nyoci_missing_h 32 | 33 | #if HAVE_CONFIG_H 34 | #include 35 | #endif 36 | 37 | #if !defined(NYOCI_BEGIN_C_DECLS) || !defined(NYOCI_END_C_DECLS) 38 | #if defined(__cplusplus) 39 | #define NYOCI_BEGIN_C_DECLS extern "C" { 40 | #define NYOCI_END_C_DECLS } 41 | #else 42 | #define NYOCI_BEGIN_C_DECLS 43 | #define NYOCI_END_C_DECLS 44 | #endif 45 | #endif 46 | 47 | #include 48 | #include 49 | #include // For ssize_t 50 | #include 51 | 52 | NYOCI_BEGIN_C_DECLS 53 | 54 | #if !HAVE_CONFIG_H 55 | 56 | #ifndef HAVE_STPNCPY 57 | #define HAVE_STPNCPY ((defined(linux) || (!defined(__APPLE__) && !defined(__AVR__))) && !defined(__SDCC)) 58 | #endif 59 | 60 | #ifndef HAVE_STRDUP 61 | #define HAVE_STRDUP (!defined(__SDCC)) 62 | #endif 63 | 64 | #ifndef HAVE_ALLOCA 65 | #define HAVE_ALLOCA (!defined(__SDCC)) 66 | #endif 67 | 68 | #ifndef HAVE_STRTOL 69 | #define HAVE_STRTOL (!defined(__SDCC)) 70 | #endif 71 | 72 | #if !NYOCI_AVOID_PRINTF 73 | #ifndef HAVE_VSNPRINTF 74 | #define HAVE_VSNPRINTF (!defined(__SDCC)) 75 | #endif 76 | 77 | #endif //!HAVE_CONFIG_H 78 | 79 | #if defined(HAVE_ALLOCA_H) && !defined(HAVE_ALLOCA) 80 | #define HAVE_ALLOCA HAVE_ALLOCA_H 81 | #endif 82 | 83 | #if !NYOCI_AVOID_PRINTF && !HAVE_VSNPRINTF && !defined(vsnprintf) 84 | #warning VSNPRINTF NOT IMPLEMENTED, VSPRINTF COULD OVERFLOW! 85 | #define vsnprintf(d,n,fmt,lst) vsprintf(d,fmt,lst) 86 | #endif 87 | #endif 88 | 89 | #if !NYOCI_AVOID_MALLOC 90 | #if !HAVE_STRDUP && !defined(strdup) 91 | #define strdup(...) ___nyoci_strdup(__VA_ARGS__) 92 | char* ___nyoci_strdup(const char* cstr); 93 | #endif 94 | 95 | #if !HAVE_STRNDUP && !defined(strndup) 96 | #define strndup(...) ___nyoci_strndup(__VA_ARGS__) 97 | char* ___nyoci_strndup(const char* cstr,size_t maxlen); 98 | #endif 99 | #endif //!NYOCI_AVOID_MALLOC 100 | 101 | #if !HAVE_STPNCPY && !defined(stpncpy) 102 | #define stpncpy(...) ___nyoci_stpncpy(__VA_ARGS__) 103 | char* ___nyoci_stpncpy(char* dest, const char* src, size_t len); 104 | #endif 105 | 106 | #ifndef MIN 107 | #if defined(__GCC_VERSION__) 108 | #define MIN(a, \ 109 | b) ({ __typeof__(a)_a = (a); __typeof__(b)_b = (b); _a < \ 110 | _b ? _a : _b; }) 111 | #else 112 | #define MIN(a,b) ((a)<(b)?(a):(b)) // NAUGHTY!...but compiles 113 | #endif 114 | #endif 115 | 116 | #ifndef MAX 117 | #if defined(__GCC_VERSION__) 118 | #define MAX(a, \ 119 | b) ({ __typeof__(a)_a = (a); __typeof__(b)_b = (b); _a > \ 120 | _b ? _a : _b; }) 121 | #else 122 | #define MAX(a,b) ((a)<(b)?(b):(a)) // NAUGHTY!...but compiles 123 | #endif 124 | #endif 125 | 126 | NYOCI_END_C_DECLS 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-opts.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-opts.h 2 | ** @author Robert Quattlebaum 3 | ** @brief LibNyoci Build Options 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef __NYOCI_OPS_H__ 31 | #define __NYOCI_OPS_H__ 32 | 33 | /*****************************************************************************/ 34 | // MARK: - LibNyoci Build Parameters 35 | 36 | //#define NYOCI_AVOID_MALLOC 1 37 | //#define NYOCI_AVOID_PRINTF 1 38 | //#define ASSERT_MACROS_USE_VANILLA_PRINTF 1 39 | //#define DEBUG 1 40 | //#define VERBOSE_DEBUG 41 | //#define NYOCI_EMBEDDED 1 42 | //#define NYOCI_USE_BSD_SOCKETS 1 43 | //#define NYOCI_PLAT_NET_POSIX_FAMILY AF_INET 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-session.c: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-session.c 2 | ** @author Robert Quattlebaum 3 | ** @brief Session tracking 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #if HAVE_CONFIG_H 31 | #include 32 | #endif 33 | 34 | #include "assert-macros.h" 35 | #include "libnyoci.h" 36 | #include "nyoci-internal.h" 37 | #include "nyoci-missing.h" 38 | 39 | #include 40 | 41 | nyoci_session_type_t 42 | nyoci_session_type_from_uri_scheme(const char* uri_scheme) 43 | { 44 | nyoci_session_type_t ret = NYOCI_SESSION_TYPE_NIL; 45 | 46 | #if NYOCI_DTLS 47 | if (strequal_const(uri_scheme, COAP_URI_SCHEME_COAPS)) { 48 | ret = NYOCI_SESSION_TYPE_DTLS; 49 | } else 50 | #endif 51 | 52 | #if NYOCI_TCP 53 | if (strequal_const(uri_scheme, COAP_URI_SCHEME_COAP_TCP)) { 54 | ret = NYOCI_SESSION_TYPE_TCP; 55 | } else 56 | #endif 57 | 58 | #if NYOCI_TLS 59 | if (strequal_const(uri_scheme, COAP_URI_SCHEME_COAPS_TCP)) { 60 | ret = NYOCI_SESSION_TYPE_TLS; 61 | } else 62 | #endif 63 | 64 | if (strequal_const(uri_scheme, COAP_URI_SCHEME_COAP)) { 65 | ret = NYOCI_SESSION_TYPE_UDP; 66 | } 67 | return ret; 68 | } 69 | 70 | uint16_t 71 | nyoci_default_port_from_session_type(nyoci_session_type_t type) 72 | { 73 | uint16_t ret = 0; 74 | 75 | switch (type) { 76 | case NYOCI_SESSION_TYPE_UDP: ret = COAP_DEFAULT_PORT; break; 77 | #if NYOCI_DTLS 78 | case NYOCI_SESSION_TYPE_DTLS: ret = COAP_DEFAULT_TLS_PORT; break; 79 | #endif 80 | #if NYOCI_TCP 81 | case NYOCI_SESSION_TYPE_TCP: ret = COAP_DEFAULT_PORT; break; 82 | #endif 83 | #if NYOCI_TLS 84 | case NYOCI_SESSION_TYPE_TLS: ret = COAP_DEFAULT_TLS_PORT; break; 85 | #endif 86 | default: break; 87 | } 88 | return ret; 89 | } 90 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-session.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-session.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Session tracking 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef NYOCI_nyoci_session_h 31 | #define NYOCI_nyoci_session_h 32 | 33 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 34 | #error "Do not include this header directly, include instead" 35 | #endif 36 | 37 | NYOCI_BEGIN_C_DECLS 38 | 39 | /*! @addtogroup nyoci 40 | ** @{ 41 | */ 42 | #define NYOCI_SESSION_TYPE_FLAG_SECURE (1<<4) 43 | #define NYOCI_SESSION_TYPE_FLAG_MULTICAST (1<<5) 44 | #define NYOCI_SESSION_TYPE_FLAG_RELIABLE (1<<6) 45 | 46 | typedef enum { 47 | NYOCI_SESSION_TYPE_NIL = 0, 48 | NYOCI_SESSION_TYPE_UDP = 1 | NYOCI_SESSION_TYPE_FLAG_MULTICAST, 49 | NYOCI_SESSION_TYPE_TCP = 2 | NYOCI_SESSION_TYPE_FLAG_RELIABLE, 50 | NYOCI_SESSION_TYPE_DTLS = 3 | NYOCI_SESSION_TYPE_FLAG_SECURE, 51 | NYOCI_SESSION_TYPE_TLS = 4 | NYOCI_SESSION_TYPE_FLAG_RELIABLE | NYOCI_SESSION_TYPE_FLAG_SECURE, 52 | } nyoci_session_type_t; 53 | 54 | #define nyoci_session_type_supports_multicast(x) (((x)&NYOCI_SESSION_TYPE_FLAG_MULTICAST)==NYOCI_SESSION_TYPE_FLAG_MULTICAST) 55 | #define nyoci_session_type_is_reliable(x) (((x)&NYOCI_SESSION_TYPE_FLAG_RELIABLE)==NYOCI_SESSION_TYPE_FLAG_RELIABLE) 56 | 57 | NYOCI_INTERNAL_EXTERN nyoci_session_type_t nyoci_session_type_from_uri_scheme(const char* uri_scheme); 58 | 59 | //! Returns the default port number for the given session type. 60 | NYOCI_INTERNAL_EXTERN uint16_t nyoci_default_port_from_session_type(nyoci_session_type_t type); 61 | 62 | /*! @} */ 63 | 64 | NYOCI_END_C_DECLS 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/libnyoci/nyoci-status.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-status.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Session tracking 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef NYOCI_STATUS_HEADER_INCLUDED 31 | #define NYOCI_STATUS_HEADER_INCLUDED 1 32 | 33 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 34 | #error "Do not include this header directly, include instead" 35 | #endif 36 | 37 | NYOCI_BEGIN_C_DECLS 38 | 39 | /*! @addtogroup nyoci 40 | ** @{ 41 | */ 42 | 43 | enum { 44 | NYOCI_STATUS_OK = 0, //!< Success. No error. 45 | NYOCI_STATUS_FAILURE = -1, //!< Unspecified failure. 46 | NYOCI_STATUS_INVALID_ARGUMENT = -2, //!< An argument or parameter was out of spec. 47 | NYOCI_STATUS_UNSUPPORTED_URI = -4, //!< The given URI is unsupported. 48 | NYOCI_STATUS_ERRNO = -5, //!< Unix socket error. (errno) 49 | NYOCI_STATUS_MALLOC_FAILURE = -6, //!< Out of memory. 50 | NYOCI_STATUS_TRANSACTION_INVALIDATED = -7, 51 | NYOCI_STATUS_TIMEOUT = -8, //!< Operation was taking too long. 52 | NYOCI_STATUS_NOT_IMPLEMENTED = -9, //!< Feature hasn't been implemented. 53 | NYOCI_STATUS_NOT_FOUND = -10, 54 | NYOCI_STATUS_H_ERRNO = -11, 55 | NYOCI_STATUS_RESPONSE_NOT_ALLOWED = -12, 56 | NYOCI_STATUS_BAD_HOSTNAME = -13, 57 | NYOCI_STATUS_LOOP_DETECTED = -14, 58 | NYOCI_STATUS_BAD_ARGUMENT = -15, 59 | NYOCI_STATUS_HOST_LOOKUP_FAILURE = -16, 60 | NYOCI_STATUS_MESSAGE_TOO_BIG = -17, 61 | NYOCI_STATUS_NOT_ALLOWED = -18, 62 | NYOCI_STATUS_URI_PARSE_FAILURE = -19, 63 | NYOCI_STATUS_WAIT_FOR_DNS = -20, 64 | NYOCI_STATUS_BAD_OPTION = -21, 65 | NYOCI_STATUS_DUPE = -22, 66 | NYOCI_STATUS_RESET = -23, 67 | NYOCI_STATUS_ASYNC_RESPONSE = -24, 68 | NYOCI_STATUS_UNAUTHORIZED = -25, 69 | NYOCI_STATUS_BAD_PACKET = -26, 70 | NYOCI_STATUS_MULTICAST_NOT_SUPPORTED = -27, 71 | NYOCI_STATUS_WAIT_FOR_SESSION = -28, 72 | NYOCI_STATUS_SESSION_ERROR = -29, 73 | NYOCI_STATUS_SESSION_CLOSED = -30, 74 | NYOCI_STATUS_OUT_OF_SESSIONS = -31, 75 | NYOCI_STATUS_UNSUPPORTED_MEDIA_TYPE = -32, 76 | //! When returned from a resend callback (in a transaction), stop sending packets without invalidate the transaction 77 | NYOCI_STATUS_STOP_RESENDING = -33 78 | }; 79 | 80 | typedef int nyoci_status_t; 81 | 82 | NYOCI_API_EXTERN coap_code_t nyoci_convert_status_to_result_code(nyoci_status_t status); 83 | 84 | NYOCI_API_EXTERN const char* nyoci_status_to_cstr(nyoci_status_t x); 85 | 86 | /*! @} */ 87 | 88 | NYOCI_END_C_DECLS 89 | 90 | #endif // NYOCI_STATUS_HEADER_INCLUDED -------------------------------------------------------------------------------- /src/libnyoci/nyoci-timer.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-timer.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Timer scheduling and management 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #ifndef __NYOCI_TIMER_H__ 31 | #define __NYOCI_TIMER_H__ 1 32 | 33 | #include "ll.h" 34 | #include "btree.h" 35 | 36 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 37 | #error "Do not include this header directly, include instead" 38 | #endif 39 | 40 | #if NYOCI_SINGLETON 41 | // On embedded systems, we know we will always only have 42 | // a single nyoci instance, so we can save a considerable 43 | // amount of stack spaces by simply removing the first argument 44 | // from many functions. In order to make things as maintainable 45 | // as possible, these macros do all of the work for us. 46 | #define nyoci_schedule_timer(self,...) nyoci_schedule_timer(__VA_ARGS__) 47 | #define nyoci_invalidate_timer(self,...) nyoci_invalidate_timer(__VA_ARGS__) 48 | #define nyoci_handle_timers(self,...) nyoci_handle_timers(__VA_ARGS__) 49 | #define nyoci_timer_is_scheduled(self,...) nyoci_timer_is_scheduled(__VA_ARGS__) 50 | #endif 51 | 52 | #ifndef MSEC_PER_SEC 53 | #define MSEC_PER_SEC (1000) 54 | #endif 55 | 56 | #ifndef USEC_PER_MSEC 57 | #define USEC_PER_MSEC (1000) 58 | #endif 59 | 60 | #ifndef USEC_PER_SEC 61 | #define USEC_PER_SEC (1000000) 62 | #endif 63 | 64 | NYOCI_BEGIN_C_DECLS 65 | /*! @addtogroup nyoci 66 | ** @{ 67 | */ 68 | 69 | /*! @defgroup nyoci_timer Timer API 70 | ** @{ 71 | ** @brief Timer functions. 72 | ** 73 | ** LibNyoci has two ways to represent a point in time: 74 | ** 75 | ** * Relative time (`nyoci_cms_t`), measured in milliseconds from "now". The future 76 | ** is positive and the past is negative. 77 | ** * Absolute time (`nyoci_timestamp_t`), measured from some platform-specific 78 | ** reference epoc. 79 | ** 80 | ** The relative notation is convenient for specifying timeouts and such, 81 | ** but the individual timers store their firing time in absolute time. 82 | ** You can convert between relative time and absolute time using 83 | ** `nyoci_plat_cms_to_timestamp()` and back again using `nyoci_plat_timestamp_to_cms()`. 84 | ** 85 | */ 86 | 87 | typedef void (*nyoci_timer_callback_t)(nyoci_t, void*); 88 | 89 | typedef struct nyoci_timer_s { 90 | struct ll_item_s ll; 91 | nyoci_timestamp_t fire_date; 92 | void* context; 93 | nyoci_timer_callback_t callback; 94 | nyoci_timer_callback_t cancel; 95 | } *nyoci_timer_t; 96 | 97 | NYOCI_API_EXTERN nyoci_timer_t nyoci_timer_init( 98 | nyoci_timer_t self, 99 | nyoci_timer_callback_t callback, 100 | nyoci_timer_callback_t cancel, 101 | void* context 102 | ); 103 | 104 | NYOCI_API_EXTERN nyoci_status_t nyoci_schedule_timer( 105 | nyoci_t self, 106 | nyoci_timer_t timer, 107 | nyoci_cms_t cms 108 | ); 109 | 110 | NYOCI_API_EXTERN void nyoci_invalidate_timer(nyoci_t self, nyoci_timer_t timer); 111 | NYOCI_API_EXTERN nyoci_cms_t nyoci_get_timeout(nyoci_t self); 112 | NYOCI_API_EXTERN void nyoci_handle_timers(nyoci_t self); 113 | NYOCI_API_EXTERN bool nyoci_timer_is_scheduled(nyoci_t self, nyoci_timer_t timer); 114 | 115 | /*! @} */ 116 | /*! @} */ 117 | 118 | NYOCI_END_C_DECLS 119 | 120 | #endif //__NYOCI_TIMER_H__ 121 | -------------------------------------------------------------------------------- /src/libnyoci/string-utils.c: -------------------------------------------------------------------------------- 1 | /*! @file string-utils.c 2 | ** @author Robert Quattlebaum 3 | ** @brief Various string utilities 4 | ** 5 | ** Originally published 2014-8-29. 6 | ** 7 | ** This file was written by Robert Quattlebaum . 8 | ** 9 | ** This work is provided as-is. Unless otherwise provided in writing, 10 | ** Robert Quattlebaum makes no representations or warranties of any 11 | ** kind concerning this work, express, implied, statutory or otherwise, 12 | ** including without limitation warranties of title, merchantability, 13 | ** fitness for a particular purpose, non infringement, or the absence 14 | ** of latent or other defects, accuracy, or the present or absence of 15 | ** errors, whether or not discoverable, all to the greatest extent 16 | ** permissible under applicable law. 17 | ** 18 | ** To the extent possible under law, Robert Quattlebaum has waived all 19 | ** copyright and related or neighboring rights to this work. This work 20 | ** is published from the United States. 21 | ** 22 | ** I, Robert Quattlebaum, dedicate any and all copyright interest in 23 | ** this work to the public domain. I make this dedication for the 24 | ** benefit of the public at large and to the detriment of my heirs and 25 | ** successors. I intend this dedication to be an overt act of 26 | ** relinquishment in perpetuity of all present and future rights to 27 | ** this code under copyright law. In jurisdictions where this is not 28 | ** possible, I hereby release this code under the Creative Commons 29 | ** Zero (CC0) license. 30 | ** 31 | ** * 32 | */ 33 | 34 | #if HAVE_CONFIG_H 35 | #include 36 | #endif 37 | 38 | #include "nyoci-helpers.h" 39 | #include "string-utils.h" 40 | 41 | char * 42 | uint32_to_hex_cstr(char *str,uint32_t v) { 43 | char *ret = str; 44 | int i; 45 | for(i=0;i<8;i++) { 46 | *str++ = "0123456789ABCDEF"[v>>28]; 47 | v<<=4; 48 | } 49 | *str=0; 50 | return ret; 51 | } 52 | 53 | /*! Adapted from K&R's "The C Programming Language", page 60. 54 | * Somewhat naive. Make sure the string has at least 11 bytes available! */ 55 | char * 56 | uint32_to_dec_cstr(char s[],uint32_t n) { 57 | uint8_t i = 0, j; 58 | 59 | do { /* generate digits in reverse order */ 60 | s[i++] = n % 10 + '0'; /* get next digit */ 61 | } while((n /= 10) > 0); /* delete it */ 62 | s[i--] = '\0'; 63 | 64 | /* Reverse the string */ 65 | for(j = 0; j < i; j++, i--) { 66 | char x = s[j]; 67 | s[j] = s[i]; 68 | s[i] = x; 69 | } 70 | 71 | return s; 72 | } 73 | 74 | /*! Make sure the string has at least 12 bytes available! */ 75 | char * 76 | int32_to_dec_cstr(char s[],int32_t n) { 77 | if(n < 0) { 78 | s[0] = '-'; 79 | uint32_to_dec_cstr(s+1, (uint32_t)-n); 80 | return s; 81 | } 82 | return uint32_to_dec_cstr(s, (uint32_t)n); 83 | } 84 | 85 | bool 86 | str2bool(const char* value) 87 | { 88 | if ( value[0] == '1' 89 | || value[0] == 't' 90 | || value[0] == 'T' 91 | || value[0] == 'y' 92 | || value[0] == 'T' 93 | ) { 94 | return true; 95 | } else if ( value[0] == '0' 96 | || value[0] == 'f' 97 | || value[0] == 'F' 98 | || value[0] == 'n' 99 | || value[0] == 'N' 100 | ) { 101 | return false; 102 | } 103 | 104 | return false; 105 | } 106 | -------------------------------------------------------------------------------- /src/libnyoci/string-utils.h: -------------------------------------------------------------------------------- 1 | /*! @file string-utils.h 2 | ** @author Robert Quattlebaum 3 | ** @brief Various string utilities 4 | ** 5 | ** Originally published 2014-8-29. 6 | ** 7 | ** This file was written by Robert Quattlebaum . 8 | ** 9 | ** This work is provided as-is. Unless otherwise provided in writing, 10 | ** Robert Quattlebaum makes no representations or warranties of any 11 | ** kind concerning this work, express, implied, statutory or otherwise, 12 | ** including without limitation warranties of title, merchantability, 13 | ** fitness for a particular purpose, non infringement, or the absence 14 | ** of latent or other defects, accuracy, or the present or absence of 15 | ** errors, whether or not discoverable, all to the greatest extent 16 | ** permissible under applicable law. 17 | ** 18 | ** To the extent possible under law, Robert Quattlebaum has waived all 19 | ** copyright and related or neighboring rights to this work. This work 20 | ** is published from the United States. 21 | ** 22 | ** I, Robert Quattlebaum, dedicate any and all copyright interest in 23 | ** this work to the public domain. I make this dedication for the 24 | ** benefit of the public at large and to the detriment of my heirs and 25 | ** successors. I intend this dedication to be an overt act of 26 | ** relinquishment in perpetuity of all present and future rights to 27 | ** this code under copyright law. In jurisdictions where this is not 28 | ** possible, I hereby release this code under the Creative Commons 29 | ** Zero (CC0) license. 30 | ** 31 | ** * 32 | */ 33 | 34 | #ifndef NYOCI_string_utils_h 35 | #define NYOCI_string_utils_h 36 | 37 | #include 38 | #include 39 | 40 | #if defined(__cplusplus) 41 | extern "C" { 42 | #endif 43 | 44 | NYOCI_INTERNAL_EXTERN char * uint32_to_hex_cstr(char *str, uint32_t v); 45 | NYOCI_INTERNAL_EXTERN char * uint32_to_dec_cstr(char s[], uint32_t n); 46 | NYOCI_INTERNAL_EXTERN char * int32_to_dec_cstr(char s[], int32_t n); 47 | 48 | NYOCI_INTERNAL_EXTERN bool str2bool(const char* str); 49 | 50 | #if __AVR__ 51 | #include 52 | #define strnequal_const(a, const_b, len_a) (strncmp_P(a, PSTR(const_b),len_a) == 0) 53 | #define strequal_const(a, b) (strcmp_P(a, PSTR(b)) == 0) 54 | #define strhasprefix_const(a, b) (strncmp_P(a, PSTR(b), sizeof(b) - 1) == 0) 55 | #else 56 | #define strnequal_const(a, const_b, len_a) (strncmp(a, const_b,len_a) == 0) 57 | #define strequal_const(a, b) (strcmp(a, b) == 0) 58 | #define strhasprefix_const(a, b) (strncmp(a, b, sizeof(b) - 1) == 0) 59 | #endif 60 | 61 | #if defined(__cplusplus) 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/libnyoci/url-helpers.h: -------------------------------------------------------------------------------- 1 | /* @file url-helpers.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Originally published 2010-8-31. 5 | ** 6 | ** This file was written by Robert Quattlebaum . 7 | ** 8 | ** This work is provided as-is. Unless otherwise provided in writing, 9 | ** Robert Quattlebaum makes no representations or warranties of any 10 | ** kind concerning this work, express, implied, statutory or otherwise, 11 | ** including without limitation warranties of title, merchantability, 12 | ** fitness for a particular purpose, non infringement, or the absence 13 | ** of latent or other defects, accuracy, or the present or absence of 14 | ** errors, whether or not discoverable, all to the greatest extent 15 | ** permissible under applicable law. 16 | ** 17 | ** To the extent possible under law, Robert Quattlebaum has waived all 18 | ** copyright and related or neighboring rights to this work. This work 19 | ** is published from the United States. 20 | ** 21 | ** I, Robert Quattlebaum, dedicate any and all copyright interest in 22 | ** this work to the public domain. I make this dedication for the 23 | ** benefit of the public at large and to the detriment of my heirs and 24 | ** successors. I intend this dedication to be an overt act of 25 | ** relinquishment in perpetuity of all present and future rights to 26 | ** this code under copyright law. In jurisdictions where this is not 27 | ** possible, I hereby release this code under the Creative Commons 28 | ** Zero (CC0) license. 29 | ** 30 | ** * 31 | */ 32 | 33 | #ifndef __URL_HELPERS_H__ 34 | #define __URL_HELPERS_H__ 1 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | /*! @defgroup url-helpers URL Helpers 41 | ** @{ 42 | */ 43 | 44 | #define URL_HELPERS_MAX_URL_COMPONENTS (15) 45 | 46 | #define MAX_URL_SIZE (256) 47 | 48 | /*! Perfoms a URL encoding of the given string. 49 | ** @returns Number of bytes in encoded string 50 | */ 51 | NYOCI_INTERNAL_EXTERN size_t url_encode_cstr( 52 | char *dest, //!< [OUT] Destination C-string 53 | const char* src, //!< [IN] Must be zero-terminated. 54 | size_t dest_max_size 55 | ); 56 | 57 | NYOCI_INTERNAL_EXTERN size_t url_encode_str( 58 | char *dest, 59 | size_t dest_max_size, 60 | const char* src, //!< Length determined by `src_len`. 61 | size_t src_len 62 | ); 63 | 64 | NYOCI_INTERNAL_EXTERN size_t url_decode_str( 65 | char *dest, 66 | size_t dest_max_size, 67 | const char* src, //!< Length determined by `src_len`. 68 | size_t src_len 69 | ); 70 | 71 | /*! Perfoms a URL decoding of the given string. 72 | ** @returns Number of bytes in decoded string 73 | */ 74 | NYOCI_INTERNAL_EXTERN size_t url_decode_cstr( 75 | char *dest, 76 | const char* src, //!< Must be zero-terminated. 77 | size_t dest_max_size 78 | ); 79 | 80 | NYOCI_INTERNAL_EXTERN void url_decode_cstr_inplace(char *str); 81 | 82 | 83 | NYOCI_INTERNAL_EXTERN size_t quoted_cstr( 84 | char *dest, 85 | const char* src, //!< Must be zero-terminated. 86 | size_t dest_max_size 87 | ); 88 | 89 | NYOCI_INTERNAL_EXTERN size_t url_form_next_value( 90 | char** form_string, //!< [IN/OUT] 91 | char** key, //!< [OUT] 92 | char** value //!< [OUT] 93 | ); 94 | 95 | NYOCI_INTERNAL_EXTERN size_t url_path_next_component( 96 | char** path_string, //!< [IN/OUT] 97 | char** component //!< [OUT] 98 | ); 99 | 100 | struct url_components_s { 101 | char* protocol; 102 | char* username; 103 | char* password; 104 | char* host; 105 | char* port; 106 | char* path; 107 | char* query; 108 | }; 109 | 110 | NYOCI_INTERNAL_EXTERN int url_parse( 111 | char* url, //!< [IN] URL to parse (will be modified) 112 | struct url_components_s* components 113 | ); 114 | 115 | NYOCI_INTERNAL_EXTERN bool url_is_absolute(const char* url); 116 | 117 | NYOCI_INTERNAL_EXTERN bool url_is_root(const char* url); 118 | 119 | #if defined(__SDCC) 120 | #define path_is_absolute(path) ((path)[0] == '/') 121 | #else 122 | inline static bool path_is_absolute(const char* path) { return path[0] == '/'; } 123 | #endif 124 | 125 | //! Transforms new_url into a shorter, possibly relative, path/url. 126 | NYOCI_INTERNAL_EXTERN void url_shorten_reference( 127 | const char* current_url, 128 | char* new_url 129 | ); 130 | 131 | NYOCI_INTERNAL_EXTERN bool string_contains_colons(const char* str); 132 | 133 | NYOCI_INTERNAL_EXTERN bool url_change( 134 | char* current_url, 135 | const char* new_url 136 | ); 137 | 138 | /*! @} */ 139 | 140 | #endif // __URL_HELPERS_H__ 141 | -------------------------------------------------------------------------------- /src/libnyociextra/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AUTOMAKE_OPTIONS = subdir-objects 3 | DISTCLEANFILES = .deps Makefile 4 | 5 | lib_LTLIBRARIES = libnyociextra.la 6 | 7 | @CODE_COVERAGE_RULES@ 8 | 9 | pkgconfigdir = ${prefix}/lib/pkgconfig 10 | pkgconfig_DATA = libnyociextra.pc 11 | 12 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 13 | AM_CFLAGS = $(CFLAGS) $(CODE_COVERAGE_CFLAGS) $(HIDDEN_VISIBILITY_CFLAGS) 14 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) $(MISSING_CPPFLAGS) 15 | 16 | libnyociextra_la_SOURCES = \ 17 | nyoci-node-router.c nyoci-node-router.h \ 18 | nyoci-list.c \ 19 | nyoci-var-handler.c nyoci-var-handler.h \ 20 | $(NULL) 21 | 22 | extraincludedir = $(includedir)/libnyociextra 23 | extrainclude_HEADERS = \ 24 | nyoci-node-router.h \ 25 | nyoci-var-handler.h \ 26 | libnyociextra.h \ 27 | $(NULL) 28 | 29 | libnyociextra_la_LIBADD = $(ALLOCA) $(PTHREAD_LIBS) ../libnyoci/libnyoci.la 30 | -------------------------------------------------------------------------------- /src/libnyociextra/libnyociextra.h: -------------------------------------------------------------------------------- 1 | /*! @file libnyociextra.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef __NYOCI_EXTRA_HEADER__ 30 | #define __NYOCI_EXTRA_HEADER__ 1 31 | 32 | #include 33 | 34 | /*! @defgroup nyoci-extras LibNyoci Extras 35 | ** @{ @} 36 | */ 37 | 38 | #include 39 | #include 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/libnyociextra/libnyociextra.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: LibNyoci Extras 7 | Description: LibNyoci Extras 8 | URL: http://libnyoci.org/ 9 | Requires: libnyoci = @VERSION@ 10 | Version: @VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -lnyociextra 13 | -------------------------------------------------------------------------------- /src/libnyociextra/nyoci-var-handler.h: -------------------------------------------------------------------------------- 1 | /*! @file nyoci-var-handler.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef __NYOCI_variable_handler_H__ 30 | #define __NYOCI_variable_handler_H__ 1 31 | 32 | #include 33 | 34 | NYOCI_BEGIN_C_DECLS 35 | 36 | /*! @addtogroup nyoci-extras 37 | ** @{ 38 | */ 39 | 40 | /*! @defgroup nyoci-var-handler Variable Node 41 | ** @{ 42 | */ 43 | 44 | struct nyoci_var_handler_s; 45 | typedef struct nyoci_var_handler_s *nyoci_var_handler_t; 46 | 47 | enum { 48 | NYOCI_VAR_GET_KEY, 49 | NYOCI_VAR_CHECK_KEY, 50 | NYOCI_VAR_SET_VALUE, 51 | NYOCI_VAR_GET_VALUE, 52 | NYOCI_VAR_GET_LF_TITLE, 53 | NYOCI_VAR_GET_MAX_AGE, 54 | NYOCI_VAR_GET_ETAG, 55 | NYOCI_VAR_GET_OBSERVABLE, 56 | }; 57 | 58 | typedef nyoci_status_t (*nyoci_var_handler_func)( 59 | nyoci_var_handler_t node, 60 | uint8_t action, 61 | uint8_t i, 62 | char* value 63 | ); 64 | 65 | struct nyoci_var_handler_s { 66 | nyoci_var_handler_func func; 67 | struct nyoci_observable_s observable; 68 | }; 69 | 70 | NYOCI_API_EXTERN nyoci_status_t nyoci_var_handler_request_handler( 71 | nyoci_var_handler_t node 72 | ); 73 | 74 | /*! @} */ 75 | /*! @} */ 76 | 77 | NYOCI_END_C_DECLS 78 | 79 | #endif //__NYOCI_TIMER_NODE_H__ 80 | -------------------------------------------------------------------------------- /src/missing/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = fgetln.h getline.c 2 | 3 | SUBDIRS = strlcpy strlcat $(NULL) 4 | -------------------------------------------------------------------------------- /src/missing/fgetln.h: -------------------------------------------------------------------------------- 1 | /* @file fgetln.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Originally published 2012-10-24. 5 | ** 6 | ** This file was written by Robert Quattlebaum . 7 | ** 8 | ** This work is provided as-is. Unless otherwise provided in writing, 9 | ** Robert Quattlebaum makes no representations or warranties of any 10 | ** kind concerning this work, express, implied, statutory or otherwise, 11 | ** including without limitation warranties of title, merchantability, 12 | ** fitness for a particular purpose, non infringement, or the absence 13 | ** of latent or other defects, accuracy, or the present or absence of 14 | ** errors, whether or not discoverable, all to the greatest extent 15 | ** permissible under applicable law. 16 | ** 17 | ** To the extent possible under law, Robert Quattlebaum has waived all 18 | ** copyright and related or neighboring rights to this work. This work 19 | ** is published from the United States. 20 | ** 21 | ** I, Robert Quattlebaum, dedicate any and all copyright interest in 22 | ** this work to the public domain. I make this dedication for the 23 | ** benefit of the public at large and to the detriment of my heirs and 24 | ** successors. I intend this dedication to be an overt act of 25 | ** relinquishment in perpetuity of all present and future rights to 26 | ** this code under copyright law. In jurisdictions where this is not 27 | ** possible, I hereby release this code under the Creative Commons 28 | ** Zero (CC0) license. 29 | ** 30 | ** * 31 | ** 32 | ** ------------------------------------------------------------------- 33 | ** 34 | ** This is a simple implementation of the BSD function `fgetln()`, 35 | ** for use on operating systems which do not have a copy. 36 | ** 37 | ** Man page URL: 38 | ** 39 | ** NOTE: This implementation is *NOT* thread safe! 40 | */ 41 | 42 | #include 43 | 44 | #if !defined(HAVE_FGETLN) && defined(__DARWIN_C_LEVEL) && (__DARWIN_C_LEVEL>=__DARWIN_C_FULL) 45 | #define HAVE_FGETLN 1 46 | #endif 47 | 48 | #if !defined(fgetln) && !HAVE_FGETLN 49 | static char * 50 | fgetln_(FILE *stream, size_t *len) { 51 | static char* linep = NULL; 52 | static size_t linecap = 0; 53 | ssize_t length = getline(&linep,&linecap,stream); 54 | if(length==-1) { 55 | free(linep); 56 | linep = NULL; 57 | linecap = 0; 58 | length = 0; 59 | } 60 | if(len) 61 | *len = length; 62 | return linep; 63 | } 64 | #define fgetln fgetln_ 65 | #endif 66 | -------------------------------------------------------------------------------- /src/missing/getline.c: -------------------------------------------------------------------------------- 1 | /* GNU mailutils - a suite of utilities for electronic mail 2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Library Public License as published by 6 | the Free Software Foundation; either version 2, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 | 18 | /* First implementation by Alain Magloire */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /* Default value for line length. */ 25 | static const int line_size = 128; 26 | 27 | ssize_t 28 | getdelim (char **lineptr, size_t *n, int delim, FILE *stream) 29 | { 30 | int indx = 0; 31 | int c; 32 | 33 | /* Sanity checks. */ 34 | if (lineptr == NULL || n == NULL || stream == NULL) 35 | return -1; 36 | 37 | /* Allocate the line the first time. */ 38 | if (*lineptr == NULL) 39 | { 40 | *lineptr = malloc (line_size); 41 | if (*lineptr == NULL) 42 | return -1; 43 | *n = line_size; 44 | } 45 | 46 | /* Clear the line. */ 47 | memset (*lineptr, '\0', *n); 48 | 49 | while ((c = getc (stream)) != EOF) 50 | { 51 | /* Check if more memory is needed. */ 52 | if (indx >= *n) 53 | { 54 | *lineptr = realloc (*lineptr, *n + line_size); 55 | if (*lineptr == NULL) 56 | { 57 | return -1; 58 | } 59 | /* Clear the rest of the line. */ 60 | memset(*lineptr + *n, '\0', line_size); 61 | *n += line_size; 62 | } 63 | 64 | /* Push the result in the line. */ 65 | (*lineptr)[indx++] = c; 66 | 67 | /* Bail out. */ 68 | if (c == delim) 69 | { 70 | break; 71 | } 72 | } 73 | return (c == EOF) ? -1 : indx; 74 | } 75 | 76 | ssize_t 77 | getline (char **lineptr, size_t *n, FILE *stream) 78 | { 79 | return getdelim (lineptr, n, '\n', stream); 80 | } 81 | 82 | #ifdef STANDALONE 83 | int main(void) 84 | { 85 | FILE * fp; 86 | char * line = NULL; 87 | size_t len = 0; 88 | ssize_t read; 89 | fp = fopen("/etc/passwd", "r"); 90 | if (fp == NULL) 91 | exit(EXIT_FAILURE); 92 | while ((read = getline(&line, &len, fp)) != -1) { 93 | printf("Retrieved line of length %zu :\n", read); 94 | printf("%s", line); 95 | } 96 | if (line) 97 | free(line); 98 | return EXIT_SUCCESS; 99 | } 100 | #endif 101 | -------------------------------------------------------------------------------- /src/missing/strlcat/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016, The OpenThread Authors. 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # 3. Neither the name of the copyright holder nor the 13 | # names of its contributors may be used to endorse or promote products 14 | # derived from this software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | # 28 | 29 | check_PROGRAMS = strlcat_test 30 | strlcat_test_SOURCES = strlcat_test.c 31 | strlcat_test_CPPFLAGS = \ 32 | $(AM_CPPFLAGS) \ 33 | $(MISSING_CPPFLAGS) \ 34 | $(NULL) 35 | strlcat_test_LDADD = $(NULL) 36 | 37 | TESTS = strlcat_test 38 | 39 | if MISSING_STRLCAT 40 | noinst_LTLIBRARIES = libstrlcat.la 41 | libstrlcat_la_SOURCES = \ 42 | strlcat.c \ 43 | strlcat.h \ 44 | $(NULL) 45 | libstrlcat_la_CPPFLAGS = \ 46 | $(AM_CPPFLAGS) \ 47 | $(MISSING_CPPFLAGS) \ 48 | $(NULL) 49 | strlcat_test_LDADD += libstrlcat.la 50 | endif 51 | 52 | if MISSING_STRLCAT 53 | strlcat_test_LDADD += ../strlcpy/libstrlcpy.la 54 | endif 55 | -------------------------------------------------------------------------------- /src/missing/strlcat/strlcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, The OpenThread Authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "strlcat.h" 29 | #include "../strlcpy/strlcpy.h" 30 | 31 | size_t strlcat(char *dest, const char *src, size_t size) 32 | { 33 | size_t len = strlen(dest); 34 | 35 | if (len < size - 1) 36 | { 37 | return (len + strlcpy(dest + len, src, size - len)); 38 | } 39 | 40 | return len + strlen(src); 41 | } 42 | -------------------------------------------------------------------------------- /src/missing/strlcat/strlcat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, The OpenThread Authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef MISSING_STRLCAT_HEADER_INCLUDED 29 | #define MISSING_STRLCAT_HEADER_INCLUDED 1 30 | 31 | #include 32 | 33 | #ifndef HAVE_STRLCAT 34 | #define HAVE_STRLCAT 1 35 | 36 | #ifdef strlcat 37 | #undef strlcat 38 | #endif 39 | 40 | #define strlcat ___missing_strlcat 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | size_t strlcat(char *dest, const char *src, size_t size); 47 | 48 | #ifdef __cplusplus 49 | } // extern "C" 50 | #endif 51 | 52 | #endif // HAVE_STRLCPY 53 | 54 | #endif // MISSING_STRLCPY_HEADER_INCLUDED 55 | -------------------------------------------------------------------------------- /src/missing/strlcat/strlcat_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, The OpenThread Authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include "string.h" 31 | 32 | int main(void) 33 | { 34 | char string_a[8] = "foo"; 35 | char string_b[8] = "barbar"; 36 | size_t ret = 0; 37 | int errors = 0; 38 | 39 | ret = strlcat(string_a, string_b, sizeof(string_a)); 40 | 41 | if (0 != strcmp(string_a, "foobarb")) 42 | { 43 | printf("strcmp failed\n"); 44 | errors++; 45 | } 46 | 47 | if (ret != 9) 48 | { 49 | printf("strlcat return value is wrong (%d)\n", (int)ret); 50 | errors++; 51 | } 52 | 53 | if (errors != 0) 54 | { 55 | printf("FAIL\n"); 56 | return EXIT_FAILURE; 57 | } 58 | 59 | printf("OK\n"); 60 | return EXIT_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /src/missing/strlcpy/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016, The OpenThread Authors. 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # 3. Neither the name of the copyright holder nor the 13 | # names of its contributors may be used to endorse or promote products 14 | # derived from this software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | # 28 | 29 | check_PROGRAMS = strlcpy_test 30 | strlcpy_test_SOURCES = strlcpy_test.c 31 | strlcpy_test_CPPFLAGS = $(MISSING_CPPFLAGS) 32 | 33 | TESTS = strlcpy_test 34 | 35 | if MISSING_STRLCPY 36 | noinst_LTLIBRARIES = libstrlcpy.la 37 | libstrlcpy_la_SOURCES = \ 38 | strlcpy.c \ 39 | strlcpy.h \ 40 | $(NULL) 41 | strlcpy_test_LDADD = libstrlcpy.la 42 | endif 43 | -------------------------------------------------------------------------------- /src/missing/strlcpy/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, The OpenThread Authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "strlcpy.h" 29 | 30 | size_t strlcpy(char *dest, const char *src, size_t size) 31 | { 32 | const size_t slen = strlen(src); 33 | 34 | if (size != 0) 35 | { 36 | size--; 37 | 38 | if (slen < size) 39 | { 40 | size = slen; 41 | } 42 | 43 | if (size != 0) 44 | { 45 | memcpy(dest, src, size); 46 | } 47 | 48 | dest[size] = 0; 49 | } 50 | 51 | return slen; 52 | } 53 | -------------------------------------------------------------------------------- /src/missing/strlcpy/strlcpy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, The OpenThread Authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef MISSING_STRLCPY_HEADER_INCLUDED 29 | #define MISSING_STRLCPY_HEADER_INCLUDED 1 30 | 31 | #include 32 | 33 | #ifndef HAVE_STRLCPY 34 | #define HAVE_STRLCPY 1 35 | 36 | #ifdef strlcpy 37 | #undef strlcpy 38 | #endif 39 | 40 | #define strlcpy ___missing_strlcpy 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | extern size_t strlcpy(char *dest, const char *src, size_t size); 47 | 48 | #ifdef __cplusplus 49 | } // extern "C" 50 | #endif 51 | 52 | #endif // HAVE_STRLCPY 53 | 54 | #endif // MISSING_STRLCPY_HEADER_INCLUDED 55 | -------------------------------------------------------------------------------- /src/missing/strlcpy/strlcpy_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, The OpenThread Authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include "string.h" 31 | 32 | int main(void) 33 | { 34 | char string_a[8] = "foo"; 35 | char string_b[] = "barbarbar"; 36 | size_t ret = 0; 37 | int errors = 0; 38 | 39 | ret = strlcpy(string_a, string_b, sizeof(string_a)); 40 | 41 | if (0 != strcmp(string_a, "barbarb")) 42 | { 43 | printf("strcmp failed\n"); 44 | errors++; 45 | } 46 | 47 | if (ret != 9) 48 | { 49 | printf("strlcpy return value is wrong (%d)\n", (int)ret); 50 | errors++; 51 | } 52 | 53 | if (errors != 0) 54 | { 55 | printf("FAIL\n"); 56 | return EXIT_FAILURE; 57 | } 58 | 59 | printf("OK\n"); 60 | return EXIT_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /src/nyocictl/Makefile.am: -------------------------------------------------------------------------------- 1 | @CODE_COVERAGE_RULES@ 2 | 3 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 4 | AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) 5 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) 6 | 7 | bin_PROGRAMS = nyocictl 8 | 9 | nyocictl_SOURCES = main.c cmd_list.c cmd_get.c cmd_post.c help.c cmd_repeat.c cmd_delete.c 10 | nyocictl_SOURCES += cmd_delete.h cmd_get.h cmd_list.h cmd_post.h cmd_repeat.h help.h nyocictl.h 11 | nyocictl_LDADD = ../libnyoci/libnyoci.la $(MISSING_LIBADD) 12 | nyocictl_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCLUDES) $(MISSING_CPPFLAGS) 13 | 14 | DISTCLEANFILES = .deps Makefile 15 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_delete.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cmd_delete.c 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 8/17/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | /* This file is a total mess and needs to be cleaned up! */ 11 | 12 | #if HAVE_CONFIG_H 13 | #include 14 | #endif 15 | 16 | #include "assert-macros.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "help.h" 24 | #include "cmd_delete.h" 25 | #include 26 | #include 27 | #include "nyocictl.h" 28 | 29 | /* 30 | static arg_list_item_t option_list[] = { 31 | { 'h', "help",NULL,"Print Help" }, 32 | { 0 } 33 | }; 34 | */ 35 | 36 | static int gRet; 37 | static sig_t previous_sigint_handler; 38 | static bool delete_show_headers; 39 | 40 | /* 41 | static arg_list_item_t option_list[] = { 42 | { 'h', "help",NULL,"Print Help" }, 43 | { 'c', "content-file",NULL,"Use content from the specified input source" }, 44 | { 0 } 45 | }; 46 | */ 47 | static void 48 | signal_interrupt(int sig) { 49 | gRet = ERRORCODE_INTERRUPT; 50 | signal(SIGINT, previous_sigint_handler); 51 | } 52 | 53 | static nyoci_status_t 54 | delete_response_handler( 55 | int statuscode, 56 | void* context 57 | ) { 58 | if (statuscode >= 0) { 59 | char* content = (char*)nyoci_inbound_get_content_ptr(); 60 | coap_size_t content_length = nyoci_inbound_get_content_len(); 61 | 62 | if(content_length>(nyoci_inbound_get_packet_length()-4)) { 63 | fprintf(stderr, "INTERNAL ERROR: CONTENT_LENGTH LARGER THAN PACKET_LENGTH-4! (content_length=%u, packet_length=%u)\n",content_length,nyoci_inbound_get_packet_length()); 64 | gRet = ERRORCODE_UNKNOWN; 65 | goto bail; 66 | } 67 | 68 | if (delete_show_headers) { 69 | coap_dump_header( 70 | stdout, 71 | NULL, 72 | nyoci_inbound_get_packet(), 73 | nyoci_inbound_get_packet_length() 74 | ); 75 | } 76 | 77 | if(!coap_verify_packet((void*)nyoci_inbound_get_packet(), nyoci_inbound_get_packet_length())) { 78 | fprintf(stderr, "INTERNAL ERROR: CALLBACK GIVEN INVALID PACKET!\n"); 79 | gRet = ERRORCODE_UNKNOWN; 80 | goto bail; 81 | } 82 | 83 | 84 | if (statuscode != COAP_RESULT_202_DELETED) { 85 | fprintf(stderr, "delete: Result code = %d (%s)\n", statuscode, 86 | (statuscode < 0) ? nyoci_status_to_cstr( 87 | statuscode) : coap_code_to_cstr(statuscode)); 88 | } 89 | 90 | if(content && content_length) { 91 | char contentBuffer[500]; 92 | 93 | content_length = 94 | ((content_length > sizeof(contentBuffer) - 95 | 2) ? sizeof(contentBuffer) - 2 : content_length); 96 | memcpy(contentBuffer, content, content_length); 97 | contentBuffer[content_length] = 0; 98 | 99 | if(content_length && (contentBuffer[content_length - 1] == '\n')) 100 | contentBuffer[--content_length] = 0; 101 | 102 | printf("%s\n", contentBuffer); 103 | } 104 | } 105 | 106 | bail: 107 | if (gRet == ERRORCODE_INPROGRESS) { 108 | gRet = 0; 109 | } 110 | return NYOCI_STATUS_OK; 111 | } 112 | 113 | static nyoci_status_t 114 | resend_delete_request(const char* url) { 115 | nyoci_status_t status = 0; 116 | 117 | status = nyoci_outbound_begin(nyoci_get_current_instance(), COAP_METHOD_DELETE, COAP_TRANS_TYPE_CONFIRMABLE); 118 | require_noerr(status,bail); 119 | 120 | status = nyoci_outbound_set_uri(url, 0); 121 | require_noerr(status,bail); 122 | 123 | status = nyoci_outbound_send(); 124 | require_noerr(status,bail); 125 | 126 | gRet = ERRORCODE_INPROGRESS; 127 | 128 | bail: 129 | return status; 130 | } 131 | 132 | 133 | static nyoci_transaction_t 134 | send_delete_request( 135 | nyoci_t nyoci, const char* url 136 | ) { 137 | nyoci_transaction_t ret; 138 | 139 | gRet = ERRORCODE_INPROGRESS; 140 | 141 | ret = nyoci_transaction_init( 142 | NULL, 143 | NYOCI_TRANSACTION_ALWAYS_INVALIDATE, // Flags 144 | (void*)&resend_delete_request, 145 | &delete_response_handler, 146 | (void*)url 147 | ); 148 | nyoci_transaction_begin(nyoci, ret, 30*MSEC_PER_SEC); 149 | 150 | bail: 151 | return ret; 152 | } 153 | 154 | int 155 | tool_cmd_delete( 156 | nyoci_t nyoci, int argc, char* argv[] 157 | ) { 158 | previous_sigint_handler = signal(SIGINT, &signal_interrupt); 159 | nyoci_transaction_t transaction; 160 | 161 | char url[1000] = ""; 162 | 163 | if((2 == argc) && (0 == strcmp(argv[1], "--help"))) { 164 | printf("Help not yet implemented for this command.\n"); 165 | return ERRORCODE_HELP; 166 | } 167 | 168 | gRet = ERRORCODE_UNKNOWN; 169 | 170 | if (getenv("NYOCI_CURRENT_PATH")) { 171 | strncpy(url, getenv("NYOCI_CURRENT_PATH"), sizeof(url)); 172 | } 173 | 174 | if (argc == 2) { 175 | url_change(url, argv[1]); 176 | } else { 177 | fprintf(stderr, "Bad args.\n"); 178 | gRet = ERRORCODE_BADARG; 179 | goto bail; 180 | } 181 | 182 | require((transaction=send_delete_request(nyoci, url)), bail); 183 | 184 | gRet = ERRORCODE_INPROGRESS; 185 | 186 | while(ERRORCODE_INPROGRESS == gRet) { 187 | nyoci_plat_wait(nyoci, 1000); 188 | nyoci_plat_process(nyoci); 189 | } 190 | 191 | nyoci_transaction_end(nyoci, transaction); 192 | 193 | bail: 194 | signal(SIGINT, previous_sigint_handler); 195 | return gRet; 196 | } 197 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_delete.h: -------------------------------------------------------------------------------- 1 | extern int tool_cmd_delete( 2 | nyoci_t nyoci, int argc, char* argv[]); 3 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_get.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmd_get.h 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 8/17/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | extern int tool_cmd_get( 11 | nyoci_t nyoci, int argc, char* argv[]); 12 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmd_list.h 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 8/17/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | extern int tool_cmd_list( 11 | nyoci_t nyoci, int argc, char* argv[]); 12 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_post.h: -------------------------------------------------------------------------------- 1 | extern int tool_cmd_post( 2 | nyoci_t nyoci, int argc, char* argv[]); 3 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_repeat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cmd_repeat.c 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 10/27/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | #if HAVE_CONFIG_H 11 | #include 12 | #endif 13 | 14 | /* This file is a total mess and needs to be cleaned up! */ 15 | 16 | #include "assert-macros.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "help.h" 26 | #include 27 | #include "cmd_repeat.h" 28 | #include "nyocictl.h" 29 | 30 | static arg_list_item_t option_list[] = { 31 | { 'h', "help", NULL, "Print Help" }, 32 | { 'i', "interval", "msec", 33 | "Milliseconds to wait between executions." }, 34 | { 'c', "count", "i", "Number of iterations" }, 35 | { 0, "prefix", "formatted string", "(writeme)" }, 36 | { 0 } 37 | }; 38 | 39 | static int ret = 0; 40 | static sig_t previous_sigint_handler; 41 | 42 | static void 43 | signal_interrupt(int sig) { 44 | ret = ERRORCODE_INTERRUPT; 45 | signal(SIGINT, previous_sigint_handler); 46 | } 47 | 48 | int 49 | tool_cmd_repeat( 50 | nyoci_t nyoci, int argc, char* argv[] 51 | ) { 52 | ret = 0; 53 | int i = 0; 54 | nyoci_cms_t interval = 5 * MSEC_PER_SEC; 55 | uint32_t count = 0xFFFFFFFF; 56 | const char* prefix_string = NULL; 57 | 58 | previous_sigint_handler = signal(SIGINT, &signal_interrupt); 59 | 60 | BEGIN_LONG_ARGUMENTS(ret) 61 | HANDLE_LONG_ARGUMENT("interval") interval = (int)strtol(argv[++i], NULL, 0); 62 | HANDLE_LONG_ARGUMENT("count") count = (int)strtol(argv[++i], NULL, 0); 63 | HANDLE_LONG_ARGUMENT("prefix") prefix_string = argv[++i]; 64 | 65 | HANDLE_LONG_ARGUMENT("help") { 66 | print_arg_list_help(option_list, argv[0], "[args] command [...]"); 67 | ret = ERRORCODE_HELP; 68 | goto bail; 69 | } 70 | BEGIN_SHORT_ARGUMENTS(ret) 71 | HANDLE_SHORT_ARGUMENT('i') interval = (int)strtol(argv[++i], NULL, 0); 72 | HANDLE_SHORT_ARGUMENT('c') count = (int)strtol(argv[++i], NULL, 0); 73 | 74 | HANDLE_SHORT_ARGUMENT2('h', '?') { 75 | print_arg_list_help(option_list, argv[0], "[args] command [...]"); 76 | ret = ERRORCODE_HELP; 77 | goto bail; 78 | } 79 | HANDLE_OTHER_ARGUMENT() { 80 | break; 81 | } 82 | END_ARGUMENTS 83 | 84 | require_action( 85 | i < argc, bail, { print_arg_list_help(option_list, 86 | argv[0], 87 | "[args] command [...]"); ret = ERRORCODE_HELP; }); 88 | 89 | if((0 == strcmp(argv[i], "repeat")) 90 | || (0 == strcmp(argv[i], "cd")) 91 | || (0 == strcmp(argv[i], "quit")) 92 | || (0 == strcmp(argv[i], "q")) 93 | || (0 == strcmp(argv[i], "exit")) 94 | || (0 == strcmp(argv[i], "test")) 95 | || (0 == strcmp(argv[i], "help")) 96 | ) { 97 | fprintf(stderr, 98 | "%s: error: Not allowed to repeat command \"%s\".\n", 99 | argv[0], 100 | argv[i]); 101 | ret = ERRORCODE_BADARG; 102 | goto bail; 103 | } 104 | 105 | while(count-- && (ret == 0)) { 106 | if(prefix_string) { 107 | char prefix_buffer[1000]; 108 | struct timeval tv; 109 | gettimeofday(&tv, NULL); 110 | strftime(prefix_buffer, 111 | sizeof(prefix_buffer), 112 | prefix_string, 113 | localtime(&tv.tv_sec)); 114 | fputs(prefix_buffer, stdout); 115 | } 116 | ret = exec_command(nyoci, argc - i, argv + i); 117 | 118 | nyoci_timestamp_t continue_time = nyoci_plat_cms_to_timestamp(interval); 119 | 120 | do { 121 | nyoci_plat_wait(nyoci, 122 | count ? nyoci_plat_timestamp_to_cms(continue_time) : 0); 123 | nyoci_plat_process(nyoci); 124 | } while(count && (ret == 0) && 125 | (nyoci_plat_timestamp_to_cms(continue_time) > 0)); 126 | } 127 | 128 | bail: 129 | signal(SIGINT, previous_sigint_handler); 130 | return ret; 131 | } 132 | -------------------------------------------------------------------------------- /src/nyocictl/cmd_repeat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmd_repeat.h 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 10/27/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | extern int tool_cmd_repeat( 11 | nyoci_t nyoci, int argc, char* argv[]); 12 | -------------------------------------------------------------------------------- /src/nyocictl/help.c: -------------------------------------------------------------------------------- 1 | /* 2 | * help.c 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 8/17/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | #if HAVE_CONFIG_H 11 | #include 12 | #endif 13 | 14 | #include "help.h" 15 | -------------------------------------------------------------------------------- /src/nyocictl/help.h: -------------------------------------------------------------------------------- 1 | /* 2 | * help.h 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 8/17/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | typedef struct { 14 | char shortarg; 15 | const char* longarg; 16 | const char* param; 17 | const char* desc; 18 | } arg_list_item_t; 19 | 20 | static inline void 21 | print_arg_list_help( 22 | const arg_list_item_t arg_list[], 23 | const char* command_name, 24 | const char* syntax 25 | ) { 26 | int i; 27 | const int desc_margin = 25; 28 | 29 | printf("Syntax:\n"); 30 | printf(" %s %s\n", command_name, syntax); 31 | printf("Options:\n"); 32 | for(i = 0; arg_list[i].desc; ++i) { 33 | int curr_desc_margin = desc_margin; 34 | 35 | if(arg_list[i].shortarg) 36 | printf(" -%c", arg_list[i].shortarg); 37 | else 38 | printf(" "); 39 | 40 | curr_desc_margin -= 5; 41 | 42 | if(arg_list[i].longarg) { 43 | if(arg_list[i].shortarg) 44 | printf("/"); 45 | else 46 | printf(" "); 47 | 48 | printf( "--%s", arg_list[i].longarg); 49 | 50 | curr_desc_margin -= strlen(arg_list[i].longarg) + 4; 51 | } else { 52 | curr_desc_margin -= 1; 53 | } 54 | 55 | if(arg_list[i].param) { 56 | printf(" <%s>", arg_list[i].param); 57 | curr_desc_margin -= strlen(arg_list[i].param) + 3; 58 | } 59 | 60 | if(curr_desc_margin<=0) { 61 | printf("\n"); 62 | curr_desc_margin = desc_margin; 63 | 64 | for(;curr_desc_margin>1;curr_desc_margin--) 65 | printf(" "); 66 | } else { 67 | if(curr_desc_margin-->0) 68 | printf(" "); 69 | 70 | for(;curr_desc_margin>0;curr_desc_margin--) 71 | printf("."); 72 | } 73 | 74 | printf(" %s\n", arg_list[i].desc); 75 | } 76 | } 77 | 78 | 79 | #define BEGIN_LONG_ARGUMENTS(ret) \ 80 | for(i = 1; i < argc; i++) { \ 81 | if(argv[i][0] == '-' && argv[i][1] == '-') { \ 82 | if(false) { \ 83 | } 84 | 85 | #define HANDLE_LONG_ARGUMENT(str) \ 86 | else if(strcmp(argv[i] + 2, str) == 0) 87 | 88 | #define BEGIN_SHORT_ARGUMENTS(ret) \ 89 | else { \ 90 | fprintf(stderr, \ 91 | "%s: error: Unknown command line argument \"%s\".\n", \ 92 | argv[0], \ 93 | argv[i]); \ 94 | ret = ERRORCODE_BADARG; \ 95 | goto bail; \ 96 | } \ 97 | } else if(argv[i][0] == '-') { \ 98 | int j; \ 99 | int ii = i; \ 100 | for(j = 1; j && argv[ii][j]; j++) { \ 101 | switch(argv[ii][j]) { \ 102 | default: \ 103 | fprintf(stderr, \ 104 | "%s: error: Unknown command line argument \"-%c\".\n", \ 105 | argv[0], \ 106 | argv[ii][j]); \ 107 | ret = ERRORCODE_BADARG; \ 108 | goto bail; 109 | 110 | #define HANDLE_SHORT_ARGUMENT(chr) \ 111 | break; case chr: 112 | 113 | #define HANDLE_SHORT_ARGUMENT2(chr, chr2) \ 114 | break; case chr: case chr2: 115 | 116 | #define HANDLE_OTHER_ARGUMENT() \ 117 | break; \ 118 | } \ 119 | } \ 120 | } else 121 | 122 | #define END_ARGUMENTS \ 123 | } 124 | -------------------------------------------------------------------------------- /src/nyocictl/nyocictl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * nyocictl.h 3 | * LibNyoci 4 | * 5 | * Created by Robert Quattlebaum on 10/8/10. 6 | * Copyright 2010 deepdarc. All rights reserved. 7 | * 8 | */ 9 | 10 | #ifndef __NYOCICTL_H__ 11 | #define __NYOCICTL_H__ 1 12 | 13 | #if HAVE_CONFIG_H 14 | #include 15 | #endif 16 | 17 | #include 18 | 19 | #define ERRORCODE_OK (0) 20 | #define ERRORCODE_HELP (1) 21 | #define ERRORCODE_BADARG (2) 22 | #define ERRORCODE_NOCOMMAND (3) 23 | #define ERRORCODE_UNKNOWN (4) 24 | #define ERRORCODE_BADCOMMAND (5) 25 | #define ERRORCODE_NOREADLINE (6) 26 | #define ERRORCODE_QUIT (7) 27 | #define ERRORCODE_INIT_FAILURE (8) 28 | #define ERRORCODE_TIMEOUT (9) 29 | #define ERRORCODE_COAP_ERROR (10) 30 | 31 | #define ERRORCODE_INTERRUPT (128+SIGINT) 32 | #define ERRORCODE_SIGHUP (128+SIGHUP) 33 | 34 | 35 | #define ERRORCODE_INPROGRESS (127) 36 | 37 | extern int exec_command( 38 | nyoci_t nyoci, int argc, char * argv[]); 39 | 40 | extern bool show_headers; 41 | 42 | #endif // __NYOCICTL_H__ 43 | -------------------------------------------------------------------------------- /src/plat-net/posix/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AUTOMAKE_OPTIONS = subdir-objects 3 | DISTCLEANFILES = .deps Makefile 4 | 5 | @CODE_COVERAGE_RULES@ 6 | 7 | noinst_LTLIBRARIES = libnyoci-plat-net.la 8 | 9 | libnyoci_plat_net_la_CFLAGS = $(AM_CFLAGS) $(CODE_COVERAGE_CFLAGS) $(HIDDEN_VISIBILITY_CFLAGS) 10 | libnyoci_plat_net_la_CPPFLAGS = $(AM_CPPFLAGS) $(NYOCI_CPPFLAGS) $(OPENSSL_INCLUDES) 11 | libnyoci_plat_net_la_LDFLAGS = $(AM_LDFLAGS) $(CODE_COVERAGE_LDFLAGS) 12 | 13 | libnyoci_plat_net_la_SOURCES = \ 14 | nyoci-plat-net-internal.h \ 15 | nyoci-plat-net.c \ 16 | nyoci-plat-net.h \ 17 | $(NULL) 18 | 19 | pkginclude_HEADERS = \ 20 | nyoci-plat-net.h \ 21 | nyoci-plat-net-internal.h \ 22 | $(NULL) 23 | -------------------------------------------------------------------------------- /src/plat-net/posix/nyoci-plat-net-internal.h: -------------------------------------------------------------------------------- 1 | /* @file nyoci-plat-bsd-internal.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_nyoci_plat_bsd_internal_h 30 | #define NYOCI_nyoci_plat_bsd_internal_h 31 | 32 | #define __USE_GNU 1 33 | #define __APPLE_USE_RFC_3542 1 34 | 35 | #include "libnyoci.h" 36 | 37 | #if NYOCI_DTLS 38 | #include "nyoci-plat-tls.h" 39 | #endif // if NYOCI_DTLS 40 | 41 | #include 42 | #include 43 | 44 | #ifndef NYOCI_PLAT_NET_POSIX_FAMILY 45 | #define NYOCI_PLAT_NET_POSIX_FAMILY AF_INET6 46 | #endif 47 | 48 | #if NYOCI_SINGLETON 49 | #define nyoci_internal_multicast_joinleave(self,...) nyoci_internal_multicast_joinleave(__VA_ARGS__) 50 | #endif 51 | 52 | 53 | #define NYOCI_ADDR_NTOP(str, len, addr) inet_ntop(NYOCI_PLAT_NET_POSIX_FAMILY, addr , str, len-1) 54 | 55 | #if NYOCI_PLAT_NET_POSIX_FAMILY == AF_INET6 56 | #define ___nyoci_len sin6_len 57 | #define ___nyoci_family sin6_family 58 | #define NYOCI_IS_ADDR_MULTICAST(addrptr) (IN6_IS_ADDR_MULTICAST(addrptr) || (IN6_IS_ADDR_V4MAPPED(addrptr) && ((addrptr)->s6_addr[12] & 0xF0)==0xE0)) 59 | #define NYOCI_IS_ADDR_LOOPBACK(addrptr) (IN6_IS_ADDR_LOOPBACK(addrptr) || (IN6_IS_ADDR_V4MAPPED(addrptr) && (addrptr)->s6_addr[12] == 127)) 60 | #define NYOCI_IS_ADDR_UNSPECIFIED(addrptr) IN6_IS_ADDR_UNSPECIFIED(addrptr) 61 | 62 | #define NYOCI_COAP_MULTICAST_ALLDEVICES_ADDR COAP_MULTICAST_IP6_LL_ALLDEVICES 63 | 64 | #ifdef IPV6_RECVPKTINFO 65 | #define NYOCI_RECVPKTINFO IPV6_RECVPKTINFO 66 | #endif 67 | #ifdef IPV6_PKTINFO 68 | #define NYOCI_PKTINFO IPV6_PKTINFO 69 | #endif 70 | #define NYOCI_IPPROTO IPPROTO_IPV6 71 | 72 | #elif NYOCI_PLAT_NET_POSIX_FAMILY == AF_INET 73 | #define ___nyoci_len sin_len 74 | #define ___nyoci_family sin_family 75 | #ifdef IP_RECVPKTINFO 76 | #define NYOCI_RECVPKTINFO IP_RECVPKTINFO 77 | #endif 78 | #ifdef IP_PKTINFO 79 | #define NYOCI_PKTINFO IP_PKTINFO 80 | #endif 81 | #define NYOCI_IPPROTO IPPROTO_IPV4 82 | 83 | #define NYOCI_IS_ADDR_MULTICAST(addrptr) ((*(const uint8_t*)(addrptr)&0xF0)==224) 84 | #define NYOCI_IS_ADDR_UNSPECIFIED(addrptr) (*(const uint32_t*)(addrptr)==0) 85 | #define NYOCI_IS_ADDR_LOOPBACK(addrptr) (*(const uint8_t*)(addrptr)==127) 86 | #define NYOCI_COAP_MULTICAST_ALLDEVICES_ADDR COAP_MULTICAST_IP4_ALLDEVICES 87 | 88 | #else // NYOCI_PLAT_NET_POSIX_FAMILY 89 | #error Unsupported value for NYOCI_PLAT_NET_POSIX_FAMILY 90 | #endif // NYOCI_PLAT_NET_POSIX_FAMILY 91 | 92 | NYOCI_BEGIN_C_DECLS 93 | 94 | struct nyoci_plat_s { 95 | int mcfd_v6; //!< For multicast 96 | int mcfd_v4; //!< For multicast 97 | 98 | int fd_udp; 99 | 100 | #if defined(NYOCI_PLAT_TLS) 101 | int fd_dtls; 102 | void* context_dtls; 103 | struct nyoci_plat_tls_s ssl; 104 | #endif 105 | 106 | void* current_session; 107 | 108 | nyoci_sockaddr_t sockaddr_local; 109 | nyoci_sockaddr_t sockaddr_remote; 110 | nyoci_session_type_t session_type; 111 | 112 | #if NYOCI_PLAT_NET_POSIX_FAMILY==AF_INET6 113 | struct in6_pktinfo pktinfo; 114 | #elif NYOCI_PLAT_NET_POSIX_FAMILY==AF_INET 115 | struct in_pktinfo pktinfo; 116 | #endif 117 | 118 | char outbound_packet_bytes[NYOCI_MAX_PACKET_LENGTH+1]; 119 | }; 120 | 121 | 122 | NYOCI_INTERNAL_EXTERN ssize_t sendtofrom( 123 | int fd, 124 | const void *data, size_t len, int flags, 125 | const struct sockaddr * saddr_to, socklen_t socklen_to, 126 | const struct sockaddr * saddr_from, socklen_t socklen_from 127 | ); 128 | 129 | NYOCI_END_C_DECLS 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /src/plat-net/posix/nyoci-plat-net.h: -------------------------------------------------------------------------------- 1 | /* @file nyoci-plat-bsd.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_nyoci_plat_bsd_h 30 | #define NYOCI_nyoci_plat_bsd_h 31 | 32 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 33 | #error "Do not include this header directly, include instead" 34 | #endif 35 | 36 | #define __USE_GNU 1 37 | #define __APPLE_USE_RFC_3542 1 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #if NYOCI_SINGLETON 46 | #define nyoci_plat_update_fdsets(self,...) nyoci_plat_update_fdsets(__VA_ARGS__) 47 | #endif 48 | 49 | #ifndef NYOCI_PLAT_NET_POSIX_FAMILY 50 | #define NYOCI_PLAT_NET_POSIX_FAMILY AF_INET6 51 | #endif 52 | 53 | NYOCI_BEGIN_C_DECLS 54 | 55 | #if NYOCI_PLAT_NET_POSIX_FAMILY == AF_INET6 56 | typedef struct in6_addr nyoci_addr_t; 57 | typedef struct sockaddr_in6 nyoci_sockaddr_t; 58 | #define nyoci_addr sin6_addr 59 | #define nyoci_port sin6_port 60 | #elif NYOCI_PLAT_NET_POSIX_FAMILY == AF_INET 61 | typedef struct in_addr nyoci_addr_t; 62 | typedef struct sockaddr_in nyoci_sockaddr_t; 63 | #define nyoci_addr sin_addr 64 | #define nyoci_port sin_port 65 | #else // NYOCI_PLAT_NET_POSIX_FAMILY 66 | #error Unsupported value for NYOCI_PLAT_NET_POSIX_FAMILY 67 | #endif // NYOCI_PLAT_NET_POSIX_FAMILY 68 | 69 | NYOCI_END_C_DECLS 70 | 71 | #if defined(__KAME__) 72 | #define NYOCI_SOCKADDR_INIT { sizeof(nyoci_sockaddr_t), NYOCI_PLAT_NET_POSIX_FAMILY } 73 | #else 74 | #define NYOCI_SOCKADDR_INIT { NYOCI_PLAT_NET_POSIX_FAMILY } 75 | #endif 76 | 77 | #include "nyoci-plat-net-func.h" 78 | 79 | NYOCI_BEGIN_C_DECLS 80 | 81 | //! Gets the file descriptor for the UDP socket. 82 | /*! Useful for implementing asynchronous operation using select(), 83 | ** poll(), or other async mechanisms. */ 84 | NYOCI_API_EXTERN int nyoci_plat_get_fd(nyoci_t self); 85 | 86 | //! Support for `select()` style asynchronous operation 87 | NYOCI_API_EXTERN nyoci_status_t nyoci_plat_update_fdsets( 88 | nyoci_t self, 89 | fd_set *read_fd_set, 90 | fd_set *write_fd_set, 91 | fd_set *error_fd_set, 92 | int *fd_count, 93 | nyoci_cms_t *timeout 94 | ); 95 | 96 | NYOCI_END_C_DECLS 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/plat-net/uip/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AUTOMAKE_OPTIONS = subdir-objects 3 | DISTCLEANFILES = .deps Makefile 4 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) 5 | 6 | @CODE_COVERAGE_RULES@ 7 | 8 | noinst_LTLIBRARIES = libnyoci-plat-net.la 9 | 10 | libnyoci_plat_net_la_CFLAGS = $(AM_CFLAGS) $(CODE_COVERAGE_CFLAGS) $(HIDDEN_VISIBILITY_CFLAGS) 11 | libnyoci_plat_net_la_LDFLAGS = $(AM_LDFLAGS) $(CODE_COVERAGE_LDFLAGS) 12 | 13 | libnyoci_plat_net_la_SOURCES = \ 14 | nyoci-plat-net-internal.h \ 15 | nyoci-plat-net.c \ 16 | nyoci-plat-net.h \ 17 | $(NULL) 18 | 19 | pkginclude_HEADERS = \ 20 | nyoci-plat-net.h \ 21 | nyoci-plat-net-internal.h \ 22 | $(NULL) 23 | -------------------------------------------------------------------------------- /src/plat-net/uip/nyoci-plat-net-internal.h: -------------------------------------------------------------------------------- 1 | /* @file nyoci-plat-uip.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_nyoci_plat_uip_internal_h 30 | #define NYOCI_nyoci_plat_uip_internal_h 31 | 32 | #include "net/ip/uip.h" 33 | 34 | #if !defined(htonl) 35 | #define htonl(x) uip_htonl(x) 36 | #define ntohl(x) uip_ntohl(x) 37 | #define htons(x) uip_htons(x) 38 | #define ntohs(x) uip_ntohs(x) 39 | #endif 40 | 41 | #if !UIP_CONF_IPV6 42 | 43 | #ifndef uip_is_addr_mcast 44 | #define uip_is_addr_mcast(addrptr) (*(const uint8_t*)(addrptr)==224) 45 | #endif 46 | 47 | #ifndef uip_is_addr_unspecified 48 | #define uip_is_addr_unspecified(addrptr) (*(addrptr)==0) 49 | #endif 50 | 51 | #ifndef uip_is_addr_loopback 52 | #define uip_is_addr_loopback(addrptr) (*(const uint8_t*)(addrptr)==127) 53 | #endif 54 | #endif 55 | 56 | #define NYOCI_IS_ADDR_MULTICAST uip_is_addr_mcast 57 | #define NYOCI_IS_ADDR_UNSPECIFIED uip_is_addr_unspecified 58 | #define NYOCI_IS_ADDR_LOOPBACK uip_is_addr_loopback 59 | 60 | #if UIP_CONF_IPV6 61 | #define NYOCI_COAP_MULTICAST_ALLDEVICES_ADDR COAP_MULTICAST_IP6_LL_ALLDEVICES 62 | #else 63 | #define NYOCI_COAP_MULTICAST_ALLDEVICES_ADDR COAP_MULTICAST_IP4_ALLDEVICES 64 | #endif 65 | 66 | NYOCI_BEGIN_C_DECLS 67 | 68 | struct nyoci_plat_s { 69 | struct uip_udp_conn* udp_conn; 70 | nyoci_sockaddr_t sockaddr_local; 71 | nyoci_sockaddr_t sockaddr_remote; 72 | nyoci_session_type_t session_type; 73 | }; 74 | 75 | NYOCI_END_C_DECLS 76 | 77 | #if UIP_CONF_IPV6 78 | #define NYOCI_ADDR_NTOP(dest, len, addr) sprintf(dest,"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) 79 | #else 80 | #define NYOCI_ADDR_NTOP(dest, len, addr) sprintf(dest,"%u.%u.%u.%u", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3]) 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/plat-net/uip/nyoci-plat-net.h: -------------------------------------------------------------------------------- 1 | /* @file nyoci-plat-uip.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_nyoci_plat_uip_h 30 | #define NYOCI_nyoci_plat_uip_h 31 | 32 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 33 | #error "Do not include this header directly, include instead" 34 | #endif 35 | 36 | #include "net/ip/uip.h" 37 | 38 | NYOCI_BEGIN_C_DECLS 39 | 40 | #if UIP_CONF_IPV6 41 | typedef uip_ip6addr_t nyoci_addr_t; 42 | #else 43 | typedef uip_ipaddr_t nyoci_addr_t; 44 | #endif 45 | 46 | typedef struct { 47 | nyoci_addr_t nyoci_addr; 48 | uint16_t nyoci_port; 49 | } nyoci_sockaddr_t; 50 | 51 | NYOCI_API_EXTERN struct uip_udp_conn* nyoci_plat_get_udp_conn(nyoci_t self); 52 | 53 | NYOCI_BEGIN_C_DECLS 54 | 55 | #include "nyoci-plat-net-func.h" 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/plat-tls/openssl/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AUTOMAKE_OPTIONS = subdir-objects 3 | DISTCLEANFILES = .deps Makefile 4 | 5 | @CODE_COVERAGE_RULES@ 6 | 7 | noinst_LTLIBRARIES = libnyoci-plat-tls.la 8 | 9 | libnyoci_plat_tls_la_CFLAGS = $(AM_CFLAGS) $(CODE_COVERAGE_CFLAGS) $(HIDDEN_VISIBILITY_CFLAGS) 10 | libnyoci_plat_tls_la_CPPFLAGS = $(AM_CPPFLAGS) $(NYOCI_CPPFLAGS) $(OPENSSL_INCLUDES) 11 | libnyoci_plat_tls_la_LDFLAGS = $(AM_LDFLAGS) $(CODE_COVERAGE_LDFLAGS) 12 | libnyoci_plat_tls_la_LIBADD = $(AM_LIBADD) $(OPENSSL_LIBS) 13 | 14 | libnyoci_plat_tls_la_SOURCES = \ 15 | nyoci-plat-tls.c \ 16 | nyoci-plat-tls.h \ 17 | $(NULL) 18 | 19 | pkginclude_HEADERS = \ 20 | nyoci-plat-tls.h \ 21 | $(NULL) 22 | -------------------------------------------------------------------------------- /src/plat-tls/openssl/nyoci-plat-tls.h: -------------------------------------------------------------------------------- 1 | /* @file nyoci-plat-openssl.h 2 | ** @author Robert Quattlebaum 3 | ** 4 | ** Copyright (C) 2017 Robert Quattlebaum 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person 7 | ** obtaining a copy of this software and associated 8 | ** documentation files (the "Software"), to deal in the 9 | ** Software without restriction, including without limitation 10 | ** the rights to use, copy, modify, merge, publish, distribute, 11 | ** sublicense, and/or sell copies of the Software, and to 12 | ** permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall 16 | ** be included in all copies or substantial portions of the 17 | ** Software. 18 | ** 19 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 20 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 21 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 22 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef NYOCI_nyoci_plat_openssl_h 30 | #define NYOCI_nyoci_plat_openssl_h 31 | 32 | #if !defined(NYOCI_INCLUDED_FROM_LIBNYOCI_H) && !defined(BUILDING_LIBNYOCI) 33 | #error "Do not include this header directly, include instead" 34 | #endif 35 | 36 | #include 37 | 38 | #include "nyoci-timer.h" 39 | #include "btree.h" 40 | 41 | #define NYOCI_PLAT_TLS_OPENSSL 1 42 | 43 | NYOCI_BEGIN_C_DECLS 44 | 45 | struct ssl_st; 46 | struct ssl_ctx_st; 47 | 48 | typedef struct ssl_ctx_st* nyoci_plat_tls_context_t; 49 | typedef struct ssl_st* nyoci_plat_tls_session_t; 50 | 51 | /* nyoci_plat_tls_context_t and nyoci_plat_tls_session_t must 52 | ** be defined before "nyoci-plat-tls-func.h" is included. */ 53 | #include "nyoci-plat-tls-func.h" 54 | 55 | struct nyoci_openssl_session_s { 56 | struct bt_item_s bt_item; 57 | nyoci_sockaddr_t sockaddr_local; 58 | nyoci_sockaddr_t sockaddr_remote; 59 | nyoci_timestamp_t created; 60 | nyoci_timestamp_t last_activity; 61 | coap_msg_id_t msg_id; 62 | struct nyoci_timer_s dtls_timer; 63 | struct ssl_st* ssl; 64 | nyoci_status_t status; 65 | }; 66 | 67 | struct nyoci_plat_tls_s { 68 | nyoci_plat_tls_context_t ssl_ctx; 69 | 70 | // The SSL session for the current transaction 71 | struct nyoci_openssl_session_s* curr_session; 72 | 73 | // The pending SSL session for the next inbound transaction 74 | nyoci_plat_tls_session_t next_ssl; 75 | 76 | struct nyoci_openssl_session_s* sessions; 77 | 78 | nyoci_plat_tls_client_psk_callback_func client_psk_callback; 79 | void* client_psk_callback_context; 80 | nyoci_plat_tls_server_psk_callback_func server_psk_callback; 81 | void* server_psk_callback_context; 82 | }; 83 | 84 | NYOCI_END_C_DECLS 85 | 86 | #endif // NYOCI_nyoci_plat_openssl_h 87 | -------------------------------------------------------------------------------- /src/plugtest/Makefile.am: -------------------------------------------------------------------------------- 1 | @CODE_COVERAGE_RULES@ 2 | 3 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 4 | AM_CFLAGS = $(CFLAGS) $(CODE_COVERAGE_CFLAGS) 5 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) $(MISSING_CPPFLAGS) 6 | 7 | bin_PROGRAMS = nyoci-plugtest-server nyoci-plugtest-client 8 | TESTS = selftest.sh 9 | 10 | nyoci_plugtest_server_SOURCES = main-server.c plugtest-server.c plugtest-server.h 11 | nyoci_plugtest_server_LDADD = ../libnyoci/libnyoci.la ../libnyociextra/libnyociextra.la 12 | 13 | nyoci_plugtest_client_SOURCES = main-client.c 14 | nyoci_plugtest_client_LDADD = ../libnyoci/libnyoci.la 15 | 16 | 17 | TESTS_ENVIRONMENT = builddir='$(builddir)' 18 | 19 | EXTRA_DIST = selftest.sh README.md 20 | DISTCLEANFILES = .deps Makefile 21 | -------------------------------------------------------------------------------- /src/plugtest/README.md: -------------------------------------------------------------------------------- 1 | LibNyoci Plugtest Suite 2 | =================== 3 | 4 | Implements server and clients for CoAP ESTI plugtests. 5 | 6 | See https://github.com/cabo/td-coap4/ for more info. 7 | -------------------------------------------------------------------------------- /src/plugtest/plugtest-server.h: -------------------------------------------------------------------------------- 1 | /* @file plugtest-server.h 2 | ** @author Robert Quattlebaum 3 | ** @desc Plugtest Server Object Header 4 | ** 5 | ** Copyright (C) 2017 Robert Quattlebaum 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person 8 | ** obtaining a copy of this software and associated 9 | ** documentation files (the "Software"), to deal in the 10 | ** Software without restriction, including without limitation 11 | ** the rights to use, copy, modify, merge, publish, distribute, 12 | ** sublicense, and/or sell copies of the Software, and to 13 | ** permit persons to whom the Software is furnished to do so, 14 | ** subject to the following conditions: 15 | ** 16 | ** The above copyright notice and this permission notice shall 17 | ** be included in all copies or substantial portions of the 18 | ** Software. 19 | ** 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24 | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 26 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | struct plugtest_server_s { 34 | struct nyoci_node_s test; 35 | struct nyoci_node_s seg1; 36 | struct nyoci_node_s seg2; 37 | struct nyoci_node_s seg3; 38 | struct nyoci_node_s query; 39 | struct nyoci_node_s separate; 40 | struct nyoci_node_s large; 41 | struct nyoci_node_s large_update; 42 | struct nyoci_node_s large_create; 43 | struct nyoci_node_s obs; 44 | struct nyoci_timer_s obs_timer; 45 | struct nyoci_observable_s observable; 46 | }; 47 | 48 | extern nyoci_status_t plugtest_server_init(struct plugtest_server_s *self,nyoci_node_t root); 49 | -------------------------------------------------------------------------------- /src/plugtest/selftest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | MallocScribble=1 MallocPreScribble=1 MallocGuardEdges=1 MallocCheckHeapStart=1 MallocCheckHeapEach=1 MALLOC_PERTURB_=1 MALLOC_CHECK_=1 DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib "${builddir-.}/nyoci-plugtest-server" 39813 > /dev/stderr & 4 | SERVER_PID=$! 5 | 6 | trap "kill -HUP $SERVER_PID" EXIT INT TERM 7 | 8 | MallocScribble=1 MallocPreScribble=1 MallocGuardEdges=1 MallocCheckHeapStart=1 MallocCheckHeapEach=1 MALLOC_PERTURB_=1 MALLOC_CHECK_=1 DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib "${builddir-.}/nyoci-plugtest-client" coap://127.0.0.1:39813 5 > /dev/stderr 9 | RESULT=$? 10 | 11 | exit $RESULT 12 | -------------------------------------------------------------------------------- /src/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = $(CPPFLAGS) $(NYOCI_CPPFLAGS) 2 | 3 | check_PROGRAMS = 4 | 5 | @CODE_COVERAGE_RULES@ 6 | 7 | AM_LIBS = $(CODE_COVERAGE_LDFLAGS) 8 | AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) 9 | 10 | check_PROGRAMS += test-concurrency 11 | test_concurrency_SOURCES = test-concurrency.c 12 | test_concurrency_LDADD = ../libnyoci/libnyoci.la 13 | 14 | TESTS = test-concurrency 15 | 16 | DISTCLEANFILES = .deps Makefile 17 | -------------------------------------------------------------------------------- /src/version.c.in: -------------------------------------------------------------------------------- 1 | #if HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #include "version.h" 5 | 6 | const char *internal_build_source_version = SOURCE_VERSION; 7 | const char *internal_build_date = __DATE__ " " __TIME__; 8 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2015 Nest Labs, Inc. 4 | * All rights reserved. 5 | * 6 | * This document is the property of Nest. It is considered 7 | * confidential and proprietary information. 8 | * 9 | * This document may not be reproduced or transmitted in any form, 10 | * in whole or in part, without the express written permission of 11 | * Nest. 12 | * 13 | * Description: 14 | * This file... 15 | * 16 | */ 17 | 18 | #ifndef INTERNAL_VERSION_H__ 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | extern const char *internal_build_source_version; 25 | extern const char *internal_build_date; 26 | 27 | #if defined(__cplusplus) 28 | } 29 | #endif 30 | 31 | #endif // INTERNAL_VERSION_H__ 32 | --------------------------------------------------------------------------------