├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ ├── ci.yml │ ├── deploy.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── debug-build.sh ├── docker ├── Dockerfile ├── arm64.Dockerfile ├── docker-compose.yml ├── full.Dockerfile ├── gcloud.Dockerfile └── tls.Dockerfile ├── gen_timezones.py ├── gke ├── README.md ├── configmap.yaml ├── pdb.yaml ├── service.yaml └── statefulset.yaml ├── grammar ├── ace │ ├── thingsdb-code.ti │ └── thingsdb-lang.js ├── grammar.py └── vscode │ └── thingsdb-lang │ ├── .vscodeignore │ ├── CHANGELOG.md │ ├── README.md │ ├── language-configuration.json │ ├── package.json │ ├── syntaxes │ └── thingsdb.tmLanguage.json │ └── vsc-extension-quickstart.md ├── inc ├── cleri │ ├── choice.h │ ├── cleri.h │ ├── dup.h │ ├── expecting.h │ ├── grammar.h │ ├── keyword.h │ ├── kwcache.h │ ├── list.h │ ├── node.h │ ├── olist.h │ ├── optional.h │ ├── parse.h │ ├── prio.h │ ├── ref.h │ ├── regex.h │ ├── repeat.h │ ├── rule.h │ ├── sequence.h │ ├── this.h │ ├── token.h │ ├── tokens.h │ └── version.h ├── doc.h ├── doc.inline.h ├── ex.h ├── langdef │ ├── langdef.h │ └── translate.h ├── lib │ ├── http_parser.c │ ├── http_parser.h │ ├── simdasciicheck.h │ └── simdutf8check.h ├── msgpack.h ├── msgpack │ ├── fbuffer.h │ ├── gcc_atomic.h │ ├── pack.h │ ├── pack_define.h │ ├── pack_template.h │ ├── predef │ │ ├── architecture.h │ │ ├── architecture │ │ │ ├── alpha.h │ │ │ ├── arm.h │ │ │ ├── blackfin.h │ │ │ ├── convex.h │ │ │ ├── ia64.h │ │ │ ├── m68k.h │ │ │ ├── mips.h │ │ │ ├── parisc.h │ │ │ ├── ppc.h │ │ │ ├── ptx.h │ │ │ ├── pyramid.h │ │ │ ├── rs6k.h │ │ │ ├── sparc.h │ │ │ ├── superh.h │ │ │ ├── sys370.h │ │ │ ├── sys390.h │ │ │ ├── x86.h │ │ │ ├── x86 │ │ │ │ ├── 32.h │ │ │ │ └── 64.h │ │ │ └── z.h │ │ ├── compiler.h │ │ ├── compiler │ │ │ ├── borland.h │ │ │ ├── clang.h │ │ │ ├── comeau.h │ │ │ ├── compaq.h │ │ │ ├── diab.h │ │ │ ├── digitalmars.h │ │ │ ├── dignus.h │ │ │ ├── edg.h │ │ │ ├── ekopath.h │ │ │ ├── gcc.h │ │ │ ├── gcc_xml.h │ │ │ ├── greenhills.h │ │ │ ├── hp_acc.h │ │ │ ├── iar.h │ │ │ ├── ibm.h │ │ │ ├── intel.h │ │ │ ├── kai.h │ │ │ ├── llvm.h │ │ │ ├── metaware.h │ │ │ ├── metrowerks.h │ │ │ ├── microtec.h │ │ │ ├── mpw.h │ │ │ ├── nvcc.h │ │ │ ├── palm.h │ │ │ ├── pgi.h │ │ │ ├── sgi_mipspro.h │ │ │ ├── sunpro.h │ │ │ ├── tendra.h │ │ │ ├── visualc.h │ │ │ └── watcom.h │ │ ├── detail │ │ │ ├── _cassert.h │ │ │ ├── _exception.h │ │ │ ├── comp_detected.h │ │ │ ├── endian_compat.h │ │ │ ├── os_detected.h │ │ │ ├── platform_detected.h │ │ │ ├── test.h │ │ │ └── test_def.h │ │ ├── hardware.h │ │ ├── hardware │ │ │ ├── simd.h │ │ │ └── simd │ │ │ │ ├── arm.h │ │ │ │ ├── arm │ │ │ │ └── versions.h │ │ │ │ ├── ppc.h │ │ │ │ ├── ppc │ │ │ │ └── versions.h │ │ │ │ ├── x86.h │ │ │ │ ├── x86 │ │ │ │ └── versions.h │ │ │ │ ├── x86_amd.h │ │ │ │ └── x86_amd │ │ │ │ └── versions.h │ │ ├── language.h │ │ ├── language │ │ │ ├── cuda.h │ │ │ ├── objc.h │ │ │ ├── stdc.h │ │ │ └── stdcpp.h │ │ ├── library.h │ │ ├── library │ │ │ ├── c.h │ │ │ ├── c │ │ │ │ ├── _prefix.h │ │ │ │ ├── cloudabi.h │ │ │ │ ├── gnu.h │ │ │ │ ├── uc.h │ │ │ │ ├── vms.h │ │ │ │ └── zos.h │ │ │ ├── std.h │ │ │ └── std │ │ │ │ ├── _prefix.h │ │ │ │ ├── cxx.h │ │ │ │ ├── dinkumware.h │ │ │ │ ├── libcomo.h │ │ │ │ ├── modena.h │ │ │ │ ├── msl.h │ │ │ │ ├── roguewave.h │ │ │ │ ├── sgi.h │ │ │ │ ├── stdcpp3.h │ │ │ │ ├── stlport.h │ │ │ │ └── vacpp.h │ │ ├── make.h │ │ ├── os.h │ │ ├── os │ │ │ ├── aix.h │ │ │ ├── amigaos.h │ │ │ ├── android.h │ │ │ ├── beos.h │ │ │ ├── bsd.h │ │ │ ├── bsd │ │ │ │ ├── bsdi.h │ │ │ │ ├── dragonfly.h │ │ │ │ ├── free.h │ │ │ │ ├── net.h │ │ │ │ └── open.h │ │ │ ├── cygwin.h │ │ │ ├── haiku.h │ │ │ ├── hpux.h │ │ │ ├── ios.h │ │ │ ├── irix.h │ │ │ ├── linux.h │ │ │ ├── macos.h │ │ │ ├── os400.h │ │ │ ├── qnxnto.h │ │ │ ├── solaris.h │ │ │ ├── unix.h │ │ │ ├── vms.h │ │ │ └── windows.h │ │ ├── other.h │ │ ├── other │ │ │ ├── endian.h │ │ │ └── workaround.h │ │ ├── platform.h │ │ ├── platform │ │ │ ├── cloudabi.h │ │ │ ├── ios.h │ │ │ ├── mingw.h │ │ │ ├── mingw32.h │ │ │ ├── mingw64.h │ │ │ ├── windows_desktop.h │ │ │ ├── windows_phone.h │ │ │ ├── windows_runtime.h │ │ │ ├── windows_server.h │ │ │ ├── windows_store.h │ │ │ ├── windows_system.h │ │ │ └── windows_uwp.h │ │ ├── version.h │ │ └── version_number.h │ ├── sbuffer.h │ ├── sysdep.h │ ├── util.h │ ├── version.c │ ├── version.h │ └── version_master.h ├── ti.h ├── ti │ ├── access.h │ ├── api.h │ ├── api.t.h │ ├── archfile.h │ ├── archive.h │ ├── args.h │ ├── async.h │ ├── auth.h │ ├── away.h │ ├── backup.h │ ├── backups.h │ ├── build.h │ ├── cfg.h │ ├── change.h │ ├── change.t.h │ ├── changes.h │ ├── changes.inline.h │ ├── changes.t.h │ ├── clients.h │ ├── closure.h │ ├── closure.inline.h │ ├── closure.t.h │ ├── collection.h │ ├── collection.inline.h │ ├── collection.t.h │ ├── collections.h │ ├── condition.h │ ├── condition.t.h │ ├── connect.h │ ├── counters.h │ ├── cpkg.h │ ├── cpkg.inline.h │ ├── cpkg.t.h │ ├── ctask.h │ ├── data.h │ ├── datetime.h │ ├── deep.h │ ├── do.h │ ├── dump.h │ ├── enum.h │ ├── enum.inline.h │ ├── enum.t.h │ ├── enums.h │ ├── enums.inline.h │ ├── enums.t.h │ ├── evars.h │ ├── export.h │ ├── field.h │ ├── field.t.h │ ├── flags.h │ ├── fmt.h │ ├── fn │ │ ├── fn.h │ │ ├── fnabs.h │ │ ├── fnadd.h │ │ ├── fnagainat.h │ │ ├── fnagainin.h │ │ ├── fnaltraise.h │ │ ├── fnargs.h │ │ ├── fnassert.h │ │ ├── fnassign.h │ │ ├── fnat.h │ │ ├── fnbackupinfo.h │ │ ├── fnbackupsinfo.h │ │ ├── fnbackupsok.h │ │ ├── fnbase64decode.h │ │ ├── fnbase64encode.h │ │ ├── fnbitcount.h │ │ ├── fnbool.h │ │ ├── fnbytes.h │ │ ├── fncall.h │ │ ├── fncancel.h │ │ ├── fnceil.h │ │ ├── fnchangeid.h │ │ ├── fnchoice.h │ │ ├── fnclear.h │ │ ├── fnclosure.h │ │ ├── fncode.h │ │ ├── fncollectioninfo.h │ │ ├── fncollectionsinfo.h │ │ ├── fncontains.h │ │ ├── fncopy.h │ │ ├── fncos.h │ │ ├── fncount.h │ │ ├── fncounters.h │ │ ├── fndatetime.h │ │ ├── fndeep.h │ │ ├── fndel.h │ │ ├── fndelbackup.h │ │ ├── fndelcollection.h │ │ ├── fndelenum.h │ │ ├── fndelexpired.h │ │ ├── fndelmodule.h │ │ ├── fndelnode.h │ │ ├── fndelprocedure.h │ │ ├── fndeltoken.h │ │ ├── fndeltype.h │ │ ├── fndeluser.h │ │ ├── fndeploymodule.h │ │ ├── fndoc.h │ │ ├── fndup.h │ │ ├── fneach.h │ │ ├── fnelse.h │ │ ├── fnemit.h │ │ ├── fnendswith.h │ │ ├── fnenum.h │ │ ├── fnenuminfo.h │ │ ├── fnenummap.h │ │ ├── fnenumsinfo.h │ │ ├── fnequals.h │ │ ├── fnerr.h │ │ ├── fnerrors.h │ │ ├── fnevery.h │ │ ├── fnexp.h │ │ ├── fnexport.h │ │ ├── fnextend.h │ │ ├── fnextendunique.h │ │ ├── fnextract.h │ │ ├── fnfill.h │ │ ├── fnfilter.h │ │ ├── fnfind.h │ │ ├── fnfindindex.h │ │ ├── fnfirst.h │ │ ├── fnflat.h │ │ ├── fnfloat.h │ │ ├── fnfloor.h │ │ ├── fnformat.h │ │ ├── fnfuture.h │ │ ├── fnget.h │ │ ├── fngrant.h │ │ ├── fnhas.h │ │ ├── fnhasbackup.h │ │ ├── fnhascollection.h │ │ ├── fnhasenum.h │ │ ├── fnhasmodule.h │ │ ├── fnhasnode.h │ │ ├── fnhasprocedure.h │ │ ├── fnhastoken.h │ │ ├── fnhastype.h │ │ ├── fnhasuser.h │ │ ├── fnid.h │ │ ├── fnimport.h │ │ ├── fnindexof.h │ │ ├── fnint.h │ │ ├── fnisarray.h │ │ ├── fnisascii.h │ │ ├── fnisbool.h │ │ ├── fnisbytes.h │ │ ├── fnisclosure.h │ │ ├── fnisdatetime.h │ │ ├── fnisemail.h │ │ ├── fnisenum.h │ │ ├── fniserr.h │ │ ├── fnisfloat.h │ │ ├── fnisfuture.h │ │ ├── fnisinf.h │ │ ├── fnisint.h │ │ ├── fnislist.h │ │ ├── fnismodule.h │ │ ├── fnismpdata.h │ │ ├── fnisnan.h │ │ ├── fnisnil.h │ │ ├── fnisraw.h │ │ ├── fnisregex.h │ │ ├── fnisroom.h │ │ ├── fnisset.h │ │ ├── fnisstr.h │ │ ├── fnistask.h │ │ ├── fnistel.h │ │ ├── fnisthing.h │ │ ├── fnistimeval.h │ │ ├── fnistimezone.h │ │ ├── fnistuple.h │ │ ├── fnisunique.h │ │ ├── fnisurl.h │ │ ├── fnisutf8.h │ │ ├── fnjoin.h │ │ ├── fnjsondump.h │ │ ├── fnjsonload.h │ │ ├── fnkeys.h │ │ ├── fnlast.h │ │ ├── fnlen.h │ │ ├── fnlist.h │ │ ├── fnload.h │ │ ├── fnlog.h │ │ ├── fnlog10.h │ │ ├── fnlog2.h │ │ ├── fnloge.h │ │ ├── fnlower.h │ │ ├── fnmap.h │ │ ├── fnmapid.h │ │ ├── fnmaptype.h │ │ ├── fnmapwrap.h │ │ ├── fnmatch.h │ │ ├── fnmodenum.h │ │ ├── fnmodprocedure.h │ │ ├── fnmodtype.h │ │ ├── fnmoduleinfo.h │ │ ├── fnmodulesinfo.h │ │ ├── fnmove.h │ │ ├── fnmsg.h │ │ ├── fnname.h │ │ ├── fnnew.h │ │ ├── fnnewbackup.h │ │ ├── fnnewcollection.h │ │ ├── fnnewmodule.h │ │ ├── fnnewnode.h │ │ ├── fnnewprocedure.h │ │ ├── fnnewtoken.h │ │ ├── fnnewtype.h │ │ ├── fnnewuser.h │ │ ├── fnnodeinfo.h │ │ ├── fnnodesinfo.h │ │ ├── fnnow.h │ │ ├── fnnse.h │ │ ├── fnone.h │ │ ├── fnowner.h │ │ ├── fnpop.h │ │ ├── fnpow.h │ │ ├── fnproceduredoc.h │ │ ├── fnprocedureinfo.h │ │ ├── fnproceduresinfo.h │ │ ├── fnpush.h │ │ ├── fnraise.h │ │ ├── fnrand.h │ │ ├── fnrandint.h │ │ ├── fnrandstr.h │ │ ├── fnrange.h │ │ ├── fnreduce.h │ │ ├── fnrefreshmodule.h │ │ ├── fnrefs.h │ │ ├── fnregex.h │ │ ├── fnremove.h │ │ ├── fnren.h │ │ ├── fnrenamecollection.h │ │ ├── fnrenameenum.h │ │ ├── fnrenamemodule.h │ │ ├── fnrenameprocedure.h │ │ ├── fnrenametype.h │ │ ├── fnrenameuser.h │ │ ├── fnreplace.h │ │ ├── fnresetcounters.h │ │ ├── fnrestartmodule.h │ │ ├── fnrestore.h │ │ ├── fnrestrict.h │ │ ├── fnrestriction.h │ │ ├── fnreverse.h │ │ ├── fnrevoke.h │ │ ├── fnroom.h │ │ ├── fnroot.h │ │ ├── fnround.h │ │ ├── fnrun.h │ │ ├── fnsearch.h │ │ ├── fnset.h │ │ ├── fnsetargs.h │ │ ├── fnsetclosure.h │ │ ├── fnsetdefaultdeep.h │ │ ├── fnsetenum.h │ │ ├── fnsetloglevel.h │ │ ├── fnsetmoduleconf.h │ │ ├── fnsetmodulescope.h │ │ ├── fnsetname.h │ │ ├── fnsetowner.h │ │ ├── fnsetpassword.h │ │ ├── fnsettimezone.h │ │ ├── fnsettype.h │ │ ├── fnshift.h │ │ ├── fnshutdown.h │ │ ├── fnsin.h │ │ ├── fnsome.h │ │ ├── fnsort.h │ │ ├── fnsplice.h │ │ ├── fnsplit.h │ │ ├── fnsqrt.h │ │ ├── fnstartswith.h │ │ ├── fnstr.h │ │ ├── fnsum.h │ │ ├── fntan.h │ │ ├── fntask.h │ │ ├── fntasks.h │ │ ├── fntest.h │ │ ├── fnthen.h │ │ ├── fnthing.h │ │ ├── fntimeit.h │ │ ├── fntimezonesinfo.h │ │ ├── fnto.h │ │ ├── fntothing.h │ │ ├── fntotype.h │ │ ├── fntrim.h │ │ ├── fntrimleft.h │ │ ├── fntrimright.h │ │ ├── fntry.h │ │ ├── fntype.h │ │ ├── fntypeassert.h │ │ ├── fntypecount.h │ │ ├── fntypeinfo.h │ │ ├── fntypesinfo.h │ │ ├── fnunique.h │ │ ├── fnunshift.h │ │ ├── fnunwrap.h │ │ ├── fnupper.h │ │ ├── fnuserinfo.h │ │ ├── fnusersinfo.h │ │ ├── fnvalue.h │ │ ├── fnvalues.h │ │ ├── fnvmap.h │ │ ├── fnweek.h │ │ ├── fnweekday.h │ │ ├── fnwhitelistadd.h │ │ ├── fnwhitelistdel.h │ │ ├── fnwrap.h │ │ ├── fnwse.h │ │ ├── fnyday.h │ │ └── fnzone.h │ ├── forloop.h │ ├── future.h │ ├── future.inline.h │ ├── future.t.h │ ├── fwd.h │ ├── gc.h │ ├── index.h │ ├── item.h │ ├── item.t.h │ ├── mapping.h │ ├── member.h │ ├── member.inline.h │ ├── member.t.h │ ├── method.h │ ├── method.t.h │ ├── mod │ │ ├── expose.h │ │ ├── expose.t.h │ │ ├── github.h │ │ ├── github.t.h │ │ ├── manifest.h │ │ ├── manifest.t.h │ │ ├── work.h │ │ └── work.t.h │ ├── module.h │ ├── module.t.h │ ├── modules.h │ ├── name.h │ ├── name.t.h │ ├── names.h │ ├── ncache.h │ ├── nil.h │ ├── node.h │ ├── node.t.h │ ├── nodes.h │ ├── opr.h │ ├── opr │ │ ├── add.h │ │ ├── and.h │ │ ├── div.h │ │ ├── eq.h │ │ ├── ge.h │ │ ├── gt.h │ │ ├── le.h │ │ ├── lt.h │ │ ├── mod.h │ │ ├── mul.h │ │ ├── ne.h │ │ ├── oprinc.h │ │ ├── or.h │ │ ├── sl.h │ │ ├── sr.h │ │ ├── sub.h │ │ └── xor.h │ ├── pipe.h │ ├── pkg.h │ ├── pkg.t.h │ ├── preopr.h │ ├── proc.h │ ├── proc.t.h │ ├── procedure.h │ ├── procedures.h │ ├── prop.h │ ├── prop.t.h │ ├── proto.h │ ├── proto.t.h │ ├── qbind.h │ ├── qbind.t.h │ ├── qcache.h │ ├── query.h │ ├── query.inline.h │ ├── query.t.h │ ├── quorum.h │ ├── raw.h │ ├── raw.inline.h │ ├── raw.t.h │ ├── regex.h │ ├── regex.t.h │ ├── req.h │ ├── req.t.h │ ├── restore.h │ ├── room.h │ ├── room.inline.h │ ├── room.t.h │ ├── rooms.h │ ├── rpkg.h │ ├── rpkg.t.h │ ├── scope.h │ ├── scope.t.h │ ├── signals.h │ ├── spec.h │ ├── spec.inline.h │ ├── spec.t.h │ ├── store.h │ ├── store │ │ ├── storeaccess.h │ │ ├── storecollection.h │ │ ├── storecollections.h │ │ ├── storeenums.h │ │ ├── storegcollect.h │ │ ├── storemodules.h │ │ ├── storenamedrooms.h │ │ ├── storenames.h │ │ ├── storeprocedures.h │ │ ├── storestatus.h │ │ ├── storetasks.h │ │ ├── storethings.h │ │ ├── storetypes.h │ │ └── storeusers.h │ ├── str.h │ ├── stream.h │ ├── stream.t.h │ ├── sync.h │ ├── syncarchive.h │ ├── syncer.h │ ├── syncevents.h │ ├── syncfull.h │ ├── task.h │ ├── task.t.h │ ├── tasks.h │ ├── tcp.h │ ├── template.h │ ├── thing.h │ ├── thing.inline.h │ ├── thing.t.h │ ├── things.h │ ├── token.h │ ├── token.t.h │ ├── ttask.h │ ├── type.h │ ├── type.t.h │ ├── types.h │ ├── types.inline.h │ ├── types.t.h │ ├── tz.h │ ├── user.h │ ├── user.t.h │ ├── users.h │ ├── val.h │ ├── val.inline.h │ ├── val.t.h │ ├── varr.h │ ├── varr.inline.h │ ├── varr.t.h │ ├── vbool.h │ ├── verror.h │ ├── version.h │ ├── vfloat.h │ ├── vint.h │ ├── vp.t.h │ ├── vset.h │ ├── vset.inline.h │ ├── vtask.h │ ├── vtask.inline.h │ ├── vtask.t.h │ ├── vup.t.h │ ├── warn.h │ ├── watch.h │ ├── watch.t.h │ ├── web.h │ ├── whitelist.h │ ├── witem.t.h │ ├── wprop.t.h │ ├── wrap.h │ ├── wrap.inline.h │ ├── write.h │ ├── ws.h │ └── ws.t.h ├── tiinc.h └── util │ ├── argparse.h │ ├── buf.h │ ├── cfgparser.h │ ├── cryptx.h │ ├── fx.h │ ├── guid.h │ ├── imap.h │ ├── iso8601.h │ ├── link.h │ ├── lock.h │ ├── logger.h │ ├── mpack.h │ ├── mpjson.h │ ├── olist.h │ ├── omap.h │ ├── osarch.h │ ├── queue.h │ ├── rbuf.h │ ├── smap.h │ ├── strx.h │ ├── syncpart.h │ ├── util.h │ └── vec.h ├── itest ├── Dockerfile ├── example_certs │ ├── localhost-100y.cert │ └── localhost-100y.key ├── lib │ ├── __init__.py │ ├── cleanup.py │ ├── client.py │ ├── color.py │ ├── node.py │ ├── spinner.py │ ├── target.py │ ├── task.py │ ├── testbase.py │ └── vars.py ├── requirements.txt ├── run_all_tests.py ├── slow_network_test.sh ├── test_advanced.py ├── test_arguments.py ├── test_backup.py ├── test_changes.py ├── test_collection_functions.py ├── test_datetime.py ├── test_dict.py ├── test_doc_url.py ├── test_enum.py ├── test_future.py ├── test_gc.py ├── test_http_api.py ├── test_import.py ├── test_index_slice.py ├── test_math.py ├── test_migrate.py ├── test_modules.py ├── test_multi_node.py ├── test_nested.py ├── test_node_functions.py ├── test_nodes.py ├── test_operators.py ├── test_pre_restore.py ├── test_procedures.py ├── test_relations.py ├── test_restriction.py ├── test_room.py ├── test_room_wss.py ├── test_scopes.py ├── test_simple.py ├── test_statements.py ├── test_syntax.py ├── test_tasks.py ├── test_thingsdb_functions.py ├── test_type.py ├── test_types.py ├── test_user_access.py ├── test_variable.py ├── test_whitelist.py ├── test_wrap.py ├── test_ws.py ├── test_wss.py └── ws │ ├── index.html │ └── msgpack.js ├── libwebsockets ├── .gitignore ├── .sai.json ├── CMakeLists-implied-options.txt ├── CMakeLists.txt ├── Kconfig ├── LICENSE ├── Makefile.projbuild ├── README.md ├── SECURITY.md ├── changelog ├── cmake │ ├── FindGit.cmake │ ├── FindMiniz.cmake │ ├── FindOpenSSLbins.cmake │ ├── LwsCheckRequirements.cmake │ ├── UseRPMTools.cmake │ ├── libwebsockets-config-version.cmake.in │ ├── libwebsockets-config.cmake.in │ ├── lws_config.h.in │ ├── lws_config_private.h.in │ └── pico_sdk_import.cmake ├── component.mk ├── include │ ├── libwebsockets.h │ ├── libwebsockets.hxx │ └── libwebsockets │ │ ├── lws-adopt.h │ │ ├── lws-async-dns.h │ │ ├── lws-backtrace.h │ │ ├── lws-bb-i2c.h │ │ ├── lws-bb-spi.h │ │ ├── lws-button.h │ │ ├── lws-cache-ttl.h │ │ ├── lws-callbacks.h │ │ ├── lws-cgi.h │ │ ├── lws-client.h │ │ ├── lws-conmon.h │ │ ├── lws-context-vhost.h │ │ ├── lws-cose.h │ │ ├── lws-dbus.h │ │ ├── lws-diskcache.h │ │ ├── lws-display.h │ │ ├── lws-dll2.h │ │ ├── lws-dlo.h │ │ ├── lws-dsh.h │ │ ├── lws-esp32-spi.h │ │ ├── lws-eventlib-exports.h │ │ ├── lws-fault-injection.h │ │ ├── lws-freertos.h │ │ ├── lws-fts.h │ │ ├── lws-genaes.h │ │ ├── lws-gencrypto.h │ │ ├── lws-genec.h │ │ ├── lws-genhash.h │ │ ├── lws-genrsa.h │ │ ├── lws-gpio.h │ │ ├── lws-html.h │ │ ├── lws-http.h │ │ ├── lws-i2c.h │ │ ├── lws-ili9341-spi.h │ │ ├── lws-jose.h │ │ ├── lws-jpeg.h │ │ ├── lws-jrpc.h │ │ ├── lws-jwe.h │ │ ├── lws-jwk.h │ │ ├── lws-jws.h │ │ ├── lws-lecp.h │ │ ├── lws-led.h │ │ ├── lws-lejp.h │ │ ├── lws-logs.h │ │ ├── lws-lwsac.h │ │ ├── lws-map.h │ │ ├── lws-metrics.h │ │ ├── lws-misc.h │ │ ├── lws-mqtt.h │ │ ├── lws-netdev.h │ │ ├── lws-network-helper.h │ │ ├── lws-optee.h │ │ ├── lws-ota.h │ │ ├── lws-protocols-plugins.h │ │ ├── lws-purify.h │ │ ├── lws-pwm.h │ │ ├── lws-retry.h │ │ ├── lws-ring.h │ │ ├── lws-secure-streams-client.h │ │ ├── lws-secure-streams-policy.h │ │ ├── lws-secure-streams-serialization.h │ │ ├── lws-secure-streams-transport-proxy.h │ │ ├── lws-secure-streams.h │ │ ├── lws-service.h │ │ ├── lws-settings.h │ │ ├── lws-sha1-base64.h │ │ ├── lws-smd.h │ │ ├── lws-spa.h │ │ ├── lws-spd1656-spi.h │ │ ├── lws-spi.h │ │ ├── lws-ssd1306-i2c.h │ │ ├── lws-ssd1675b-spi.h │ │ ├── lws-state.h │ │ ├── lws-struct.h │ │ ├── lws-system.h │ │ ├── lws-test-sequencer.h │ │ ├── lws-threadpool.h │ │ ├── lws-timeout-timer.h │ │ ├── lws-tls-sessions.h │ │ ├── lws-tokenize.h │ │ ├── lws-uc8176-spi.h │ │ ├── lws-upng.h │ │ ├── lws-vfs.h │ │ ├── lws-write.h │ │ ├── lws-writeable.h │ │ ├── lws-ws-close.h │ │ ├── lws-ws-ext.h │ │ ├── lws-ws-state.h │ │ └── lws-x509.h ├── lgtm.yml ├── lib │ ├── CMakeLists.txt │ ├── README.md │ ├── core-net │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── adopt.c │ │ ├── client │ │ │ ├── client.c │ │ │ ├── conmon.c │ │ │ ├── connect.c │ │ │ ├── connect2.c │ │ │ ├── connect3.c │ │ │ ├── connect4.c │ │ │ └── sort-dns.c │ │ ├── close.c │ │ ├── dummy-callback.c │ │ ├── lws-dsh.c │ │ ├── network.c │ │ ├── output.c │ │ ├── pollfd.c │ │ ├── private-lib-core-net.h │ │ ├── route.c │ │ ├── service.c │ │ ├── socks5-client.c │ │ ├── sorted-usec-list.c │ │ ├── state.c │ │ ├── transport-mux-client.c │ │ ├── transport-mux-common.c │ │ ├── transport-mux-proxy.c │ │ ├── vhost.c │ │ ├── wol.c │ │ ├── wsi-timeout.c │ │ └── wsi.c │ ├── core │ │ ├── CMakeLists.txt │ │ ├── alloc.c │ │ ├── buflist.c │ │ ├── context.c │ │ ├── libwebsockets.c │ │ ├── logs.c │ │ ├── lws_dll2.c │ │ ├── lws_map.c │ │ ├── private-lib-core.h │ │ └── vfs.c │ ├── cose │ │ ├── CMakeLists.txt │ │ ├── cose_key.c │ │ ├── cose_sign.c │ │ ├── cose_sign_alg.c │ │ ├── cose_validate.c │ │ ├── cose_validate_alg.c │ │ └── private-lib-cose.h │ ├── drivers │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── button │ │ │ ├── README.md │ │ │ └── lws-button.c │ │ ├── display │ │ │ ├── README.md │ │ │ ├── ili9341-spi.c │ │ │ ├── lws-display.c │ │ │ ├── spd1656-spi.c │ │ │ ├── ssd1306-i2c.c │ │ │ ├── ssd1675b-spi.c │ │ │ └── uc8176-spi.c │ │ ├── i2c │ │ │ ├── bitbang │ │ │ │ └── lws-bb-i2c.c │ │ │ └── lws-i2c.c │ │ ├── led │ │ │ ├── README.md │ │ │ ├── led-gpio.c │ │ │ ├── led-seq.c │ │ │ └── private-lib-drivers-led.h │ │ ├── netdev │ │ │ ├── netdev.c │ │ │ └── wifi.c │ │ ├── pwm │ │ │ └── pwm.c │ │ ├── settings │ │ │ └── settings.c │ │ └── spi │ │ │ ├── bitbang │ │ │ └── lws-bb-spi.c │ │ │ └── lws-spi.c │ ├── event-libs │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── glib │ │ │ ├── CMakeLists.txt │ │ │ ├── glib.c │ │ │ └── private-lib-event-libs-glib.h │ │ ├── libev │ │ │ ├── CMakeLists.txt │ │ │ ├── libev.c │ │ │ └── private-lib-event-libs-libev.h │ │ ├── libevent │ │ │ ├── CMakeLists.txt │ │ │ ├── libevent.c │ │ │ └── private-lib-event-libs-libevent.h │ │ ├── libuv │ │ │ ├── CMakeLists.txt │ │ │ ├── libuv.c │ │ │ └── private-lib-event-libs-libuv.h │ │ ├── poll │ │ │ ├── CMakeLists.txt │ │ │ ├── poll.c │ │ │ └── private-lib-event-libs-poll.h │ │ ├── private-lib-event-libs.h │ │ ├── sdevent │ │ │ ├── CMakeLists.txt │ │ │ ├── private-lib-event-libs-sdevent.h │ │ │ └── sdevent.c │ │ └── uloop │ │ │ ├── CMakeLists.txt │ │ │ ├── private-lib-event-libs-uloop.h │ │ │ └── uloop.c │ ├── jose │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── jwe │ │ │ ├── enc │ │ │ │ ├── aescbc.c │ │ │ │ ├── aesgcm.c │ │ │ │ └── aeskw.c │ │ │ ├── jwe-ecdh-es-aeskw.c │ │ │ ├── jwe-rsa-aescbc.c │ │ │ ├── jwe-rsa-aesgcm.c │ │ │ ├── jwe.c │ │ │ └── private-lib-jose-jwe.h │ │ ├── jwk │ │ │ ├── jose_key.c │ │ │ └── jwk.c │ │ ├── jws │ │ │ ├── jose.c │ │ │ ├── jws.c │ │ │ └── private-lib-jose-jws.h │ │ └── private-lib-jose.h │ ├── misc │ │ ├── CMakeLists.txt │ │ ├── backtrace.c │ │ ├── base64-decode.c │ │ ├── cache-ttl │ │ │ ├── file.c │ │ │ ├── heap.c │ │ │ ├── lws-cache-ttl.c │ │ │ └── private-lib-misc-cache-ttl.h │ │ ├── css-lextable-strings.txt │ │ ├── css-lextable.h │ │ ├── css-prop-constants.txt │ │ ├── css-propconst-lextable.h │ │ ├── daemonize.c │ │ ├── dir.c │ │ ├── diskcache.c │ │ ├── dlo │ │ │ ├── dlo-font-mcufont.c │ │ │ ├── dlo-jpeg.c │ │ │ ├── dlo-lhp.c │ │ │ ├── dlo-png.c │ │ │ ├── dlo-rect.c │ │ │ ├── dlo-ss.c │ │ │ ├── dlo-text.c │ │ │ ├── dlo.c │ │ │ └── private-lib-drivers-display-dlo.h │ │ ├── fsmount.c │ │ ├── fts │ │ │ ├── README.md │ │ │ ├── private-lib-misc-fts.h │ │ │ ├── trie-fd.c │ │ │ └── trie.c │ │ ├── getifaddrs.c │ │ ├── getifaddrs.h │ │ ├── ieeehalfprecision.c │ │ ├── jpeg.c │ │ ├── jrpc │ │ │ ├── jrpc.c │ │ │ └── private-lib-misc-jrpc.h │ │ ├── lecp.c │ │ ├── lejp.c │ │ ├── lhp-ss.c │ │ ├── lhp.c │ │ ├── lws-ring.c │ │ ├── lws-struct-lejp.c │ │ ├── lws-struct-sqlite.c │ │ ├── lwsac │ │ │ ├── README.md │ │ │ ├── cached-file.c │ │ │ ├── lwsac.c │ │ │ ├── lwsac.cxx │ │ │ └── private-lib-misc-lwsac.h │ │ ├── minilex.c │ │ ├── peer-limits.c │ │ ├── prng.c │ │ ├── romfs.c │ │ ├── romfs.h │ │ ├── sha-1.c │ │ ├── threadpool │ │ │ ├── README.md │ │ │ └── threadpool.c │ │ ├── upng-gzip.c │ │ └── upng.c │ ├── plat │ │ ├── freertos │ │ │ ├── CMakeLists.txt │ │ │ ├── esp32 │ │ │ │ ├── drivers │ │ │ │ │ ├── gpio-esp32.c │ │ │ │ │ ├── lws-plat-gpio.h │ │ │ │ │ ├── netdev │ │ │ │ │ │ └── wifi-esp32.c │ │ │ │ │ ├── pwm-esp32.c │ │ │ │ │ ├── settings-esp32.c │ │ │ │ │ └── spi-esp32.c │ │ │ │ └── esp32-lws_ota.c │ │ │ ├── freertos-fds.c │ │ │ ├── freertos-file.c │ │ │ ├── freertos-init.c │ │ │ ├── freertos-misc.c │ │ │ ├── freertos-pipe.c │ │ │ ├── freertos-resolv.c │ │ │ ├── freertos-service.c │ │ │ ├── freertos-sockets.c │ │ │ └── private-lib-plat-freertos.h │ │ ├── optee │ │ │ ├── CMakeLists.txt │ │ │ ├── lws-plat-optee.c │ │ │ ├── network.c │ │ │ └── private-lib-plat-optee.h │ │ ├── unix │ │ │ ├── CMakeLists.txt │ │ │ ├── android │ │ │ │ └── android-resolv.c │ │ │ ├── private-lib-plat-unix.h │ │ │ ├── unix-caps.c │ │ │ ├── unix-fds.c │ │ │ ├── unix-file.c │ │ │ ├── unix-init.c │ │ │ ├── unix-misc.c │ │ │ ├── unix-pipe.c │ │ │ ├── unix-plugins.c │ │ │ ├── unix-resolv.c │ │ │ ├── unix-service.c │ │ │ ├── unix-sockets.c │ │ │ ├── unix-spawn.c │ │ │ └── unix-systemd.c │ │ └── windows │ │ │ ├── CMakeLists.txt │ │ │ ├── private-lib-plat-windows.h │ │ │ ├── windows-fds.c │ │ │ ├── windows-file.c │ │ │ ├── windows-init.c │ │ │ ├── windows-misc.c │ │ │ ├── windows-pipe.c │ │ │ ├── windows-plugins.c │ │ │ ├── windows-resolv.c │ │ │ ├── windows-service.c │ │ │ ├── windows-sockets.c │ │ │ └── windows-spawn.c │ ├── roles │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── cgi │ │ │ ├── CMakeLists.txt │ │ │ ├── cgi-server.c │ │ │ ├── ops-cgi.c │ │ │ └── private-lib-roles-cgi.h │ │ ├── dbus │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── dbus.c │ │ │ └── private-lib-roles-dbus.h │ │ ├── h1 │ │ │ ├── CMakeLists.txt │ │ │ ├── ops-h1.c │ │ │ └── private-lib-roles-h1.h │ │ ├── h2 │ │ │ ├── CMakeLists.txt │ │ │ ├── hpack.c │ │ │ ├── http2.c │ │ │ ├── huftable.h │ │ │ ├── minihuf.c │ │ │ ├── ops-h2.c │ │ │ └── private-lib-roles-h2.h │ │ ├── http │ │ │ ├── CMakeLists.txt │ │ │ ├── client │ │ │ │ └── client-http.c │ │ │ ├── compression │ │ │ │ ├── README.md │ │ │ │ ├── brotli │ │ │ │ │ └── brotli.c │ │ │ │ ├── deflate │ │ │ │ │ └── deflate.c │ │ │ │ ├── private-lib-roles-http-compression.h │ │ │ │ └── stream.c │ │ │ ├── cookie.c │ │ │ ├── date.c │ │ │ ├── header.c │ │ │ ├── lextable-strings.h │ │ │ ├── lextable.h │ │ │ ├── minilex.c │ │ │ ├── parsers.c │ │ │ ├── private-lib-roles-http.h │ │ │ └── server │ │ │ │ ├── access-log.c │ │ │ │ ├── fops-zip.c │ │ │ │ ├── lejp-conf.c │ │ │ │ ├── lws-spa.c │ │ │ │ ├── ranges.c │ │ │ │ ├── rewrite.c │ │ │ │ └── server.c │ │ ├── listen │ │ │ ├── CMakeLists.txt │ │ │ └── ops-listen.c │ │ ├── mqtt │ │ │ ├── CMakeLists.txt │ │ │ ├── client │ │ │ │ ├── client-mqtt-handshake.c │ │ │ │ └── client-mqtt.c │ │ │ ├── mqtt.c │ │ │ ├── ops-mqtt.c │ │ │ ├── primitives.c │ │ │ └── private-lib-roles-mqtt.h │ │ ├── netlink │ │ │ └── ops-netlink.c │ │ ├── pipe │ │ │ └── ops-pipe.c │ │ ├── private-lib-roles.h │ │ ├── raw-file │ │ │ ├── CMakeLists.txt │ │ │ └── ops-raw-file.c │ │ ├── raw-proxy │ │ │ ├── CMakeLists.txt │ │ │ ├── ops-raw-proxy.c │ │ │ └── private-lib-roles-raw-proxy.h │ │ ├── raw-skt │ │ │ ├── CMakeLists.txt │ │ │ └── ops-raw-skt.c │ │ └── ws │ │ │ ├── CMakeLists.txt │ │ │ ├── client-parser-ws.c │ │ │ ├── client-ws.c │ │ │ ├── ext │ │ │ ├── extension-permessage-deflate.c │ │ │ ├── extension-permessage-deflate.h │ │ │ └── extension.c │ │ │ ├── ops-ws.c │ │ │ ├── private-lib-roles-ws.h │ │ │ └── server-ws.c │ ├── secure-streams │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── cpp │ │ │ ├── README.md │ │ │ ├── lss.cxx │ │ │ ├── lssFile.cxx │ │ │ └── lssMsg.cxx │ │ ├── plugins │ │ │ └── ssp-h1url │ │ │ │ └── h1url.c │ │ ├── policy-common.c │ │ ├── policy-json.c │ │ ├── private-lib-secure-streams.h │ │ ├── protocols │ │ │ ├── README.md │ │ │ ├── ss-h1.c │ │ │ ├── ss-h2.c │ │ │ ├── ss-mqtt.c │ │ │ ├── ss-raw.c │ │ │ └── ss-ws.c │ │ ├── secure-streams.c │ │ ├── serialized │ │ │ ├── client │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── README.md │ │ │ │ ├── sspc-deserialize.c │ │ │ │ ├── sspc-transport-wsi.c │ │ │ │ ├── sspc-transport.c │ │ │ │ └── sspc.c │ │ │ └── proxy │ │ │ │ ├── proxy-deserialize.c │ │ │ │ ├── proxy-transport-wsi.c │ │ │ │ ├── proxy-transport.c │ │ │ │ └── proxy.c │ │ └── system │ │ │ ├── auth-api.amazon.com │ │ │ └── auth.c │ │ │ ├── auth-sigv4 │ │ │ └── sign.c │ │ │ ├── captive-portal-detect │ │ │ └── captive-portal-detect.c │ │ │ └── fetch-policy │ │ │ └── fetch-policy.c │ ├── system │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── async-dns │ │ │ ├── async-dns-parse.c │ │ │ ├── async-dns.c │ │ │ └── private-lib-async-dns.h │ │ ├── dhcpclient │ │ │ ├── dhcpc4.c │ │ │ ├── dhcpclient.c │ │ │ └── private-lib-system-dhcpclient.h │ │ ├── fault-injection │ │ │ ├── fault-injection.c │ │ │ └── private-lib-system-fault-injection.h │ │ ├── metrics │ │ │ ├── CMakeLists.txt │ │ │ ├── metrics.c │ │ │ └── private-lib-system-metrics.h │ │ ├── ntpclient │ │ │ └── ntpclient.c │ │ ├── ota │ │ │ └── ota.c │ │ ├── smd │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── private-lib-system-smd.h │ │ │ └── smd.c │ │ └── system.c │ └── tls │ │ ├── CMakeLists.txt │ │ ├── lws-gencrypto-common.c │ │ ├── lws-genec-common.c │ │ ├── mbedtls │ │ ├── CMakeLists.txt │ │ ├── lws-genaes.c │ │ ├── lws-gencrypto.c │ │ ├── lws-genec.c │ │ ├── lws-genhash.c │ │ ├── lws-genrsa.c │ │ ├── mbedtls-client.c │ │ ├── mbedtls-extensions.c │ │ ├── mbedtls-server.c │ │ ├── mbedtls-session.c │ │ ├── mbedtls-ssl.c │ │ ├── mbedtls-tls.c │ │ ├── mbedtls-x509.c │ │ ├── private-lib-tls-mbedtls.h │ │ └── wrapper │ │ │ ├── include │ │ │ ├── internal │ │ │ │ ├── ssl3.h │ │ │ │ ├── ssl_cert.h │ │ │ │ ├── ssl_code.h │ │ │ │ ├── ssl_dbg.h │ │ │ │ ├── ssl_lib.h │ │ │ │ ├── ssl_methods.h │ │ │ │ ├── ssl_pkey.h │ │ │ │ ├── ssl_stack.h │ │ │ │ ├── ssl_types.h │ │ │ │ ├── ssl_x509.h │ │ │ │ ├── tls1.h │ │ │ │ └── x509_vfy.h │ │ │ ├── openssl │ │ │ │ └── ssl.h │ │ │ └── platform │ │ │ │ ├── ssl_pm.h │ │ │ │ └── ssl_port.h │ │ │ ├── library │ │ │ ├── ssl_cert.c │ │ │ ├── ssl_lib.c │ │ │ ├── ssl_methods.c │ │ │ ├── ssl_pkey.c │ │ │ ├── ssl_stack.c │ │ │ └── ssl_x509.c │ │ │ └── platform │ │ │ ├── ssl_pm.c │ │ │ └── ssl_port.c │ │ ├── openssl │ │ ├── lws-genaes.c │ │ ├── lws-gencrypto.c │ │ ├── lws-genec.c │ │ ├── lws-genhash.c │ │ ├── lws-genrsa.c │ │ ├── openssl-client.c │ │ ├── openssl-server.c │ │ ├── openssl-session.c │ │ ├── openssl-ssl.c │ │ ├── openssl-tls.c │ │ ├── openssl-x509.c │ │ └── private-lib-tls-openssl.h │ │ ├── private-jit-trust.h │ │ ├── private-lib-tls.h │ │ ├── private-network.h │ │ ├── tls-client.c │ │ ├── tls-jit-trust.c │ │ ├── tls-network.c │ │ ├── tls-server.c │ │ ├── tls-sessions.c │ │ └── tls.c ├── libwebsockets.dox ├── lwsws │ ├── CMakeLists.txt │ ├── etc-logrotate.d-lwsws │ ├── etc-lwsws-conf-EXAMPLE │ ├── etc-lwsws-conf.d-localhost-EXAMPLE │ ├── main.c │ └── usr-lib-systemd-system-lwsws.service └── plugins │ ├── CMakeLists.txt │ ├── acme-client │ └── protocol_lws_acme_client.c │ ├── deaddrop │ ├── README.md │ ├── assets │ │ ├── deaddrop.css │ │ ├── deaddrop.js │ │ ├── drop.svg │ │ └── index.html │ └── protocol_lws_deaddrop.c │ ├── lwsws-logo.png │ ├── protocol_client_loopback_test.c │ ├── protocol_dumb_increment.c │ ├── protocol_fulltext_demo.c │ ├── protocol_lws_mirror.c │ ├── protocol_lws_openmetrics_export.c │ ├── protocol_lws_raw_test.c │ ├── protocol_lws_sshd_demo.c │ ├── protocol_lws_status.c │ ├── protocol_post_demo.c │ ├── raw-proxy │ ├── README.md │ └── protocol_lws_raw_proxy.c │ ├── server-status.css │ └── ssh-base │ ├── crypto │ ├── chacha.c │ ├── ed25519.c │ ├── fe25519.c │ ├── fe25519.h │ ├── ge25519.c │ ├── ge25519.h │ ├── ge25519_base.data │ ├── poly1305.c │ ├── sc25519.c │ ├── sc25519.h │ └── smult_curve25519_ref.c │ ├── include │ ├── lws-plugin-ssh.h │ ├── lws-plugin-sshd-static-build-includes.h │ └── lws-ssh.h │ ├── kex-25519.c │ ├── sshd.c │ └── telnet.c ├── main.c ├── memleak.supp ├── misc ├── Keraleeyam-Regular.ttf ├── logo_on_dark.svg ├── logo_on_white.svg ├── mkpkg.py ├── thingsdb_on_dark.svg ├── thingsdb_on_dark_h.svg └── thingsdb_on_white.svg ├── release-build.sh ├── src ├── cleri │ ├── choice.c │ ├── cleri.c │ ├── dup.c │ ├── expecting.c │ ├── grammar.c │ ├── keyword.c │ ├── kwcache.c │ ├── list.c │ ├── node.c │ ├── olist.c │ ├── optional.c │ ├── parse.c │ ├── prio.c │ ├── ref.c │ ├── regex.c │ ├── repeat.c │ ├── rule.c │ ├── sequence.c │ ├── this.c │ ├── token.c │ ├── tokens.c │ └── version.c ├── ex.c ├── langdef │ ├── compat.c │ ├── langdef.c │ └── translate.c ├── ti.c ├── ti │ ├── access.c │ ├── api.c │ ├── archfile.c │ ├── archive.c │ ├── args.c │ ├── async.c │ ├── auth.c │ ├── away.c │ ├── backup.c │ ├── backups.c │ ├── build.c │ ├── cfg.c │ ├── change.c │ ├── changes.c │ ├── clients.c │ ├── closure.c │ ├── collection.c │ ├── collections.c │ ├── condition.c │ ├── connect.c │ ├── counters.c │ ├── cpkg.c │ ├── ctask.c │ ├── datetime.c │ ├── deep.c │ ├── do.c │ ├── dump.c │ ├── enum.c │ ├── enums.c │ ├── evars.c │ ├── export.c │ ├── field.c │ ├── flags.c │ ├── fmt.c │ ├── fn.c │ ├── forloop.c │ ├── future.c │ ├── fwd.c │ ├── gc.c │ ├── index.c │ ├── item.c │ ├── mapping.c │ ├── member.c │ ├── method.c │ ├── mod │ │ ├── expose.c │ │ ├── github.c │ │ ├── manifest.c │ │ └── work.c │ ├── module.c │ ├── modules.c │ ├── name.c │ ├── names.c │ ├── ncache.c │ ├── nil.c │ ├── node.c │ ├── nodes.c │ ├── opr.c │ ├── pipe.c │ ├── pkg.c │ ├── preopr.c │ ├── proc.c │ ├── procedure.c │ ├── procedures.c │ ├── prop.c │ ├── proto.c │ ├── qbind.c │ ├── qcache.c │ ├── query.c │ ├── quorum.c │ ├── raw.c │ ├── regex.c │ ├── req.c │ ├── restore.c │ ├── room.c │ ├── rooms.c │ ├── rpkg.c │ ├── scope.c │ ├── signals.c │ ├── spec.c │ ├── store.c │ ├── store │ │ ├── storeaccess.c │ │ ├── storecollection.c │ │ ├── storecollections.c │ │ ├── storeenums.c │ │ ├── storegcollect.c │ │ ├── storemodules.c │ │ ├── storenamedrooms.c │ │ ├── storenames.c │ │ ├── storeprocedures.c │ │ ├── storestatus.c │ │ ├── storetasks.c │ │ ├── storethings.c │ │ ├── storetypes.c │ │ └── storeusers.c │ ├── stream.c │ ├── sync.c │ ├── syncarchive.c │ ├── syncer.c │ ├── syncevents.c │ ├── syncfull.c │ ├── task.c │ ├── tasks.c │ ├── tcp.c │ ├── template.c │ ├── thing.c │ ├── things.c │ ├── token.c │ ├── ttask.c │ ├── type.c │ ├── types.c │ ├── tz.c │ ├── user.c │ ├── users.c │ ├── val.c │ ├── varr.c │ ├── vbool.c │ ├── verror.c │ ├── version.c │ ├── vfloat.c │ ├── vint.c │ ├── vset.c │ ├── vtask.c │ ├── warn.c │ ├── watch.c │ ├── web.c │ ├── whitelist.c │ ├── wrap.c │ ├── write.c │ └── ws.c └── util │ ├── argparse.c │ ├── buf.c │ ├── cfgparser.c │ ├── cryptx.c │ ├── fx.c │ ├── guid.c │ ├── imap.c │ ├── iso8601.c │ ├── link.c │ ├── lock.c │ ├── logger.c │ ├── olist.c │ ├── omap.c │ ├── osarch.c │ ├── queue.c │ ├── rbuf.c │ ├── smap.c │ ├── strx.c │ ├── syncpart.c │ ├── util.c │ └── vec.c ├── test ├── _test_big │ ├── sources │ └── test_big.c ├── _test_lookup │ ├── sources │ └── test_lookup.c ├── test.h ├── test.sh ├── test_guid │ ├── sources │ └── test_guid.c ├── test_imap │ ├── sources │ └── test_imap.c ├── test_link │ ├── sources │ └── test_link.c ├── test_omap │ ├── sources │ └── test_omap.c ├── test_queue │ ├── sources │ └── test_queue.c ├── test_smap │ ├── sources │ └── test_smap.c ├── test_strx │ ├── sources │ └── test_strx.c └── test_vec │ ├── sources │ └── test_vec.c └── thingsdb.example.conf /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: cesbit 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Setup X nodes using the following configuration '...' 16 | 2. Do the following action '....' 17 | 3. See error 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Machine/OS (please complete the following information):** 26 | - OS: [e.g. Debian] 27 | - Version [e.g. Buster, AMD64] 28 | 29 | **Additional context** 30 | Add any other context about the problem here. 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Install dependencies 16 | run: | 17 | sudo apt-get update 18 | sudo apt-get install -y libuv1-dev libpcre2-dev libyajl-dev libcurl4-openssl-dev valgrind 19 | - name: Run tests 20 | run: | 21 | cd ./test/ 22 | ./test.sh 23 | - name: Compile code 24 | run: | 25 | cmake -DCMAKE_BUILD_TYPE=Debug . 26 | make 27 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "connectors/python3"] 2 | path = connectors/python3 3 | url = git@github.com:thingsdb/python-thingsdb.git 4 | [submodule "connectors/go"] 5 | path = connectors/go 6 | url = git@github.com:thingsdb/go-thingsdb.git 7 | -------------------------------------------------------------------------------- /debug-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd "$(dirname "$0")" 3 | cmake -DCMAKE_BUILD_TYPE=Debug . 4 | make 5 | -------------------------------------------------------------------------------- /gke/configmap.yaml: -------------------------------------------------------------------------------- 1 | kind: ConfigMap 2 | apiVersion: v1 3 | 4 | metadata: 5 | name: ti-config 6 | namespace: default 7 | 8 | data: 9 | service_account.json: |- 10 | { 11 | "type": "service_account", 12 | "project_id": "EXAMPLE PROJECT ID", 13 | "private_key_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 14 | "private_key": "-----BEGIN PRIVATE KEY-----\n....\n-----END PRIVATE KEY-----\n", 15 | "client_email": "thingsdb-sa@dexample-project.iam.gserviceaccount.com", 16 | "client_id": "012345678901234567890", 17 | "auth_uri": "https://accounts.google.com/o/oauth2/auth", 18 | "token_uri": "https://oauth2.googleapis.com/token", 19 | "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 20 | "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/thingsdb-sa%40example-project.iam.gserviceaccount.com" 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /gke/pdb.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: policy/v1beta1 2 | kind: PodDisruptionBudget 3 | metadata: 4 | name: thingsdb-pdb 5 | spec: 6 | maxUnavailable: 1 7 | selector: 8 | matchLabels: 9 | app: thingsdb 10 | -------------------------------------------------------------------------------- /gke/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | labels: 5 | app: thingsdb 6 | name: thingsdb 7 | spec: 8 | clusterIP: None 9 | publishNotReadyAddresses: true 10 | ports: 11 | - name: status 12 | port: 8080 13 | - name: client 14 | port: 9200 15 | - name: http 16 | port: 9210 17 | - name: node 18 | port: 9220 19 | selector: 20 | app: thingsdb 21 | -------------------------------------------------------------------------------- /grammar/ace/thingsdb-code.ti: -------------------------------------------------------------------------------- 1 | // Single line comment 2 | 3 | /* 4 | * Block comment 5 | */ 6 | 7 | 8 | .store.arr.map(|x, idx| { 9 | [x, idx]; 10 | }); 11 | 12 | b = true; 13 | n = nil; 14 | f = 4.0; 15 | i = 0x80; 16 | ss = 'String'; 17 | sd = "String"; 18 | t = { 19 | name: 'Iris', 20 | age: 6, 21 | time: now(), 22 | }; 23 | a = [0, 1, 2, 3,]; 24 | S = set([t]); 25 | 26 | .id(); 27 | 28 | refs(f); 29 | 30 | new_node('secret', '127.0.0.1', 9100); 31 | 32 | -------------------------------------------------------------------------------- /grammar/vscode/thingsdb-lang/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | .gitignore 4 | vsc-extension-quickstart.md 5 | -------------------------------------------------------------------------------- /grammar/vscode/thingsdb-lang/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "thingsdb-lang" extension will be documented in this file. 4 | 5 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. 6 | 7 | ## [Unreleased] 8 | 9 | - Initial release -------------------------------------------------------------------------------- /grammar/vscode/thingsdb-lang/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thingsdb-lang", 3 | "displayName": "ThingsDB Lang", 4 | "description": "Syntax highlighting for ThingsDB", 5 | "version": "0.0.1", 6 | "engines": { 7 | "vscode": "^1.41.0" 8 | }, 9 | "categories": [ 10 | "Programming Languages" 11 | ], 12 | "contributes": { 13 | "languages": [{ 14 | "id": "thingsdb", 15 | "aliases": ["ThingsDB", "thingsdb"], 16 | "extensions": [".ti"], 17 | "configuration": "./language-configuration.json" 18 | }], 19 | "grammars": [{ 20 | "language": "thingsdb", 21 | "scopeName": "source.ti", 22 | "path": "./syntaxes/thingsdb.tmLanguage.json" 23 | }] 24 | } 25 | } -------------------------------------------------------------------------------- /inc/cleri/choice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * choice.h - this cleri element can hold other elements and the grammar 3 | * has to choose one of them. 4 | */ 5 | #ifndef CLERI_CHOICE_H_ 6 | #define CLERI_CHOICE_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /* typedefs */ 14 | typedef struct cleri_s cleri_t; 15 | typedef struct cleri_olist_s cleri_olist_t; 16 | typedef struct cleri_choice_s cleri_choice_t; 17 | 18 | /* public functions */ 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | cleri_t * cleri_choice(uint32_t gid, int most_greedy, size_t len, ...); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | /* structs */ 30 | struct cleri_choice_s 31 | { 32 | int most_greedy; 33 | cleri_olist_t * olist; 34 | }; 35 | 36 | #endif /* CLERI_CHOICE_H_ */ -------------------------------------------------------------------------------- /inc/cleri/dup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dup.h - this cleri element can be used to duplicate an element. 3 | */ 4 | #ifndef CLERI_DUP_H_ 5 | #define CLERI_DUP_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* typedefs */ 12 | typedef struct cleri_s cleri_t; 13 | typedef struct cleri_dup_s cleri_dup_t; 14 | 15 | /* public functions */ 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | cleri_t * cleri_dup(uint32_t gid, cleri_t * cl_obj); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | /* structs */ 27 | // cleri_dup_t is defined in cleri.h 28 | 29 | #endif /* CLERI_DUP_H_ */ -------------------------------------------------------------------------------- /inc/cleri/keyword.h: -------------------------------------------------------------------------------- 1 | /* 2 | * keyword.h - cleri keyword element. 3 | */ 4 | #ifndef CLERI_KEYWORD_H_ 5 | #define CLERI_KEYWORD_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* typedefs */ 12 | typedef struct cleri_s cleri_t; 13 | typedef struct cleri_keyword_s cleri_keyword_t; 14 | 15 | /* public functions */ 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | cleri_t * cleri_keyword(uint32_t gid, const char * keyword, int ign_case); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | /* structs */ 26 | struct cleri_keyword_s 27 | { 28 | const char * keyword; 29 | int ign_case; 30 | size_t len; 31 | }; 32 | 33 | #endif /* CLERI_KEYWORD_H_ */ -------------------------------------------------------------------------------- /inc/cleri/kwcache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kwcache.h - holds keyword regular expression result while parsing. 3 | */ 4 | #ifndef CLERI_KWCACHE_H_ 5 | #define CLERI_KWCACHE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* typedefs */ 12 | typedef struct cleri_parse_s cleri_parse_t; 13 | 14 | /* private functions */ 15 | uint8_t * cleri__kwcache_new(const char * str); 16 | uint8_t cleri__kwcache_match(cleri_parse_t * pr, const char * str); 17 | void cleri__kwcache_free(uint8_t * kwcache); 18 | 19 | #endif /* CLERI_KWCACHE_H_ */ 20 | 21 | -------------------------------------------------------------------------------- /inc/cleri/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * list.h - cleri list element. 3 | */ 4 | #ifndef CLERI_LIST_H_ 5 | #define CLERI_LIST_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* typedefs */ 13 | typedef struct cleri_s cleri_t; 14 | typedef struct cleri_list_s cleri_list_t; 15 | 16 | /* public functions */ 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | cleri_t * cleri_list( 22 | uint32_t gid, 23 | cleri_t * cl_obj, 24 | cleri_t * delimiter, 25 | size_t min, 26 | size_t max, 27 | int opt_closing); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | /* structs */ 34 | struct cleri_list_s 35 | { 36 | cleri_t * cl_obj; 37 | cleri_t * delimiter; 38 | size_t min; 39 | size_t max; 40 | int opt_closing; 41 | }; 42 | 43 | #endif /* CLERI_LIST_H_ */ -------------------------------------------------------------------------------- /inc/cleri/olist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * olist.h - linked list for keeping cleri objects. 3 | */ 4 | #ifndef CLERI_OLIST_H_ 5 | #define CLERI_OLIST_H_ 6 | 7 | #include 8 | 9 | /* typedefs */ 10 | typedef struct cleri_s cleri_t; 11 | typedef struct cleri_olist_s cleri_olist_t; 12 | typedef struct cleri_olist_s cleri_olist_t; 13 | 14 | /* private functions */ 15 | cleri_olist_t * cleri__olist_new(void); 16 | int cleri__olist_append(cleri_olist_t * olist, cleri_t * cl_object); 17 | int cleri__olist_append_nref(cleri_olist_t * olist, cleri_t * cl_object); 18 | void cleri__olist_free(cleri_olist_t * olist); 19 | void cleri__olist_empty(cleri_olist_t * olist); 20 | void cleri__olist_cancel(cleri_olist_t * olist); 21 | void cleri__olist_unique(cleri_olist_t * olist); 22 | 23 | /* structs */ 24 | struct cleri_olist_s 25 | { 26 | cleri_t * cl_obj; 27 | cleri_olist_t * next; 28 | }; 29 | 30 | #endif /* CLERI_OLIST_H_ */ -------------------------------------------------------------------------------- /inc/cleri/optional.h: -------------------------------------------------------------------------------- 1 | /* 2 | * optional.h - cleri optional element. 3 | */ 4 | #ifndef CLERI_OPTIONAL_H_ 5 | #define CLERI_OPTIONAL_H_ 6 | 7 | #include 8 | #include 9 | 10 | /* typedefs */ 11 | typedef struct cleri_s cleri_t; 12 | typedef struct cleri_optional_s cleri_optional_t; 13 | 14 | /* public functions */ 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | cleri_t * cleri_optional(uint32_t gid, cleri_t * cl_obj); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | /* structs */ 26 | struct cleri_optional_s 27 | { 28 | cleri_t * cl_obj; 29 | }; 30 | 31 | #endif /* CLERI_OPTIONAL_H_ */ -------------------------------------------------------------------------------- /inc/cleri/prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * prio.h - cleri prio element. (this element create a cleri rule object 3 | * holding this prio element) 4 | */ 5 | #ifndef CLERI_PRIO_H_ 6 | #define CLERI_PRIO_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /* typedefs */ 15 | typedef struct cleri_s cleri_t; 16 | typedef struct cleri_olist_s cleri_olist_t; 17 | typedef struct cleri_prio_s cleri_prio_t; 18 | 19 | /* public functions */ 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | cleri_t * cleri_prio(uint32_t gid, size_t len, ...); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | /* structs */ 31 | struct cleri_prio_s 32 | { 33 | cleri_olist_t * olist; 34 | }; 35 | 36 | #endif /* CLERI_PRIO_H_ */ -------------------------------------------------------------------------------- /inc/cleri/ref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ref.h - cleri ref element 3 | */ 4 | #ifndef CLERI_REF_H_ 5 | #define CLERI_REF_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* typedefs */ 12 | typedef struct cleri_s cleri_t; 13 | 14 | /* public functions */ 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | cleri_t * cleri_ref(void); 20 | void cleri_ref_set(cleri_t * ref, cleri_t * cl_obj); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* CLERI_REF_H_ */ -------------------------------------------------------------------------------- /inc/cleri/regex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * regex.h - cleri regular expression element. 3 | */ 4 | #ifndef CLERI_REGEX_H_ 5 | #define CLERI_REGEX_H_ 6 | 7 | #define PCRE2_CODE_UNIT_WIDTH 8 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /* typedefs */ 15 | typedef struct cleri_s cleri_t; 16 | typedef struct cleri_regex_s cleri_regex_t; 17 | 18 | /* public functions */ 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | cleri_t * cleri_regex(uint32_t gid, const char * pattern); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | /* structs */ 30 | struct cleri_regex_s 31 | { 32 | pcre2_code * regex; 33 | pcre2_match_data * match_data; 34 | }; 35 | 36 | #endif /* CLERI_REGEX_H_ */ -------------------------------------------------------------------------------- /inc/cleri/repeat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * repeat.h - cleri regular repeat element. 3 | */ 4 | #ifndef CLERI_REPEAT_H_ 5 | #define CLERI_REPEAT_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* typedefs */ 13 | typedef struct cleri_s cleri_t; 14 | typedef struct cleri_repeat_s cleri_repeat_t; 15 | 16 | /* public functions */ 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | cleri_t * cleri_repeat(uint32_t gid, cleri_t * cl_obj, size_t min, size_t max); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | /* structs */ 28 | struct cleri_repeat_s 29 | { 30 | cleri_t * cl_obj; 31 | size_t min; 32 | size_t max; 33 | }; 34 | 35 | #endif /* CLERI_REPEAT_H_ */ -------------------------------------------------------------------------------- /inc/cleri/sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sequence.h - cleri sequence element. 3 | */ 4 | #ifndef CLERI_SEQUENCE_H_ 5 | #define CLERI_SEQUENCE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* typedefs */ 13 | typedef struct cleri_s cleri_t; 14 | typedef struct cleri_olist_s cleri_olist_t; 15 | typedef struct cleri_sequence_s cleri_sequence_t; 16 | 17 | /* public functions */ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | cleri_t * cleri_sequence(uint32_t gid, size_t len, ...); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | /* structs */ 29 | struct cleri_sequence_s 30 | { 31 | cleri_olist_t * olist; 32 | }; 33 | 34 | #endif /* CLERI_SEQUENCE_H_ */ -------------------------------------------------------------------------------- /inc/cleri/this.h: -------------------------------------------------------------------------------- 1 | /* 2 | * this.h - cleri THIS element. there should be only one single instance 3 | * of this which can even be shared over different grammars. 4 | * Always use this element using its constant CLERI_THIS and 5 | * somewhere within a prio element. 6 | */ 7 | #ifndef CLERI_THIS_H_ 8 | #define CLERI_THIS_H_ 9 | 10 | #include 11 | #include 12 | 13 | /* typedefs */ 14 | typedef struct cleri_s cleri_t; 15 | 16 | /* public THIS */ 17 | extern cleri_t * CLERI_THIS; 18 | 19 | #endif /* CLERI_THIS_H_ */ -------------------------------------------------------------------------------- /inc/cleri/token.h: -------------------------------------------------------------------------------- 1 | /* 2 | * token.h - cleri token element. note that one single char will parse 3 | * slightly faster compared to tokens containing more characters. 4 | * (be careful a token should not match the keyword regular 5 | * expression) 6 | */ 7 | #ifndef CLERI_TOKEN_H_ 8 | #define CLERI_TOKEN_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* typedefs */ 15 | typedef struct cleri_s cleri_t; 16 | typedef struct cleri_token_s cleri_token_t; 17 | 18 | /* public functions */ 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | cleri_t * cleri_token(uint32_t gid, const char * token); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | /* structs */ 30 | struct cleri_token_s 31 | { 32 | const char * token; 33 | size_t len; 34 | }; 35 | 36 | #endif /* CLERI_TOKEN_H_ */ 37 | -------------------------------------------------------------------------------- /inc/cleri/tokens.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tokens.h - cleri tokens element. (like token but can contain more tokens 3 | * in one element) 4 | */ 5 | #ifndef CLERI_TOKENS_H_ 6 | #define CLERI_TOKENS_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | /* typedefs */ 13 | typedef struct cleri_s cleri_t; 14 | typedef struct cleri_tlist_s cleri_tlist_t; 15 | typedef struct cleri_tokens_s cleri_tokens_t; 16 | 17 | /* public functions */ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | cleri_t * cleri_tokens(uint32_t gid, const char * tokens); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | /* structs */ 29 | struct cleri_tlist_s 30 | { 31 | const char * token; 32 | size_t len; 33 | cleri_tlist_t * next; 34 | }; 35 | 36 | struct cleri_tokens_s 37 | { 38 | char * tokens; 39 | char * spaced; 40 | cleri_tlist_t * tlist; 41 | }; 42 | 43 | #endif /* CLERI_TOKENS_H_ */ -------------------------------------------------------------------------------- /inc/cleri/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * version.h - cleri version information. 3 | */ 4 | #ifndef CLERI_VERSION_H_ 5 | #define CLERI_VERSION_H_ 6 | 7 | #define CLERI_VERSION_MAJOR 1 8 | #define CLERI_VERSION_MINOR 0 9 | #define CLERI_VERSION_PATCH 2a 10 | 11 | #define VERSION__STRINGIFY(num) #num 12 | #define VERSION___STR(major,minor,patch) \ 13 | VERSION__STRINGIFY(major) "." \ 14 | VERSION__STRINGIFY(minor) "." \ 15 | VERSION__STRINGIFY(patch) 16 | /* end helpers */ 17 | 18 | /* start auto generated from above */ 19 | #define LIBCLERI_VERSION VERSION___STR( \ 20 | CLERI_VERSION_MAJOR, \ 21 | CLERI_VERSION_MINOR, \ 22 | CLERI_VERSION_PATCH) 23 | 24 | /* public funtion */ 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | const char * cleri_version(void); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* CLERI_VERSION_H_ */ 36 | -------------------------------------------------------------------------------- /inc/langdef/translate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * langdef/translate.h 3 | */ 4 | #ifndef LANGDEF_TRANSLATE_H_ 5 | #define LANGDEF_TRANSLATE_H_ 6 | 7 | #include 8 | 9 | const char * langdef_translate(cleri_t * elem); 10 | 11 | #endif /* LANGDEF_TRANSLATE_H_ */ 12 | -------------------------------------------------------------------------------- /inc/msgpack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Distributed under the Boost Software License, Version 1.0. 7 | * (See accompanying file LICENSE_1_0.txt or copy at 8 | * http://www.boost.org/LICENSE_1_0.txt) 9 | */ 10 | /** 11 | * @defgroup msgpack MessagePack C 12 | * @{ 13 | * @} 14 | */ 15 | 16 | #include "msgpack/util.h" 17 | #include "msgpack/pack.h" 18 | #include "msgpack/sbuffer.h" 19 | #include "msgpack/version.h" 20 | 21 | -------------------------------------------------------------------------------- /inc/msgpack/fbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C FILE* buffer adaptor 3 | * 4 | * Copyright (C) 2013 Vladimir Volodko 5 | * 6 | * Distributed under the Boost Software License, Version 1.0. 7 | * (See accompanying file LICENSE_1_0.txt or copy at 8 | * http://www.boost.org/LICENSE_1_0.txt) 9 | */ 10 | #ifndef MSGPACK_FBUFFER_H 11 | #define MSGPACK_FBUFFER_H 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | 20 | /** 21 | * @defgroup msgpack_fbuffer FILE* buffer 22 | * @ingroup msgpack_buffer 23 | * @{ 24 | */ 25 | 26 | static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len) 27 | { 28 | return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; 29 | } 30 | 31 | /** @} */ 32 | 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* msgpack/fbuffer.h */ 39 | -------------------------------------------------------------------------------- /inc/msgpack/gcc_atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Distributed under the Boost Software License, Version 1.0. 3 | * (See accompanying file LICENSE_1_0.txt or copy at 4 | * http://www.boost.org/LICENSE_1_0.txt) 5 | */ 6 | 7 | #ifndef MSGPACK_GCC_ATOMIC_H 8 | #define MSGPACK_GCC_ATOMIC_H 9 | 10 | #if defined(__cplusplus) 11 | extern "C" { 12 | #endif 13 | 14 | typedef int _msgpack_atomic_counter_t; 15 | 16 | int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); 17 | int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); 18 | 19 | 20 | #if defined(__cplusplus) 21 | } 22 | #endif 23 | 24 | 25 | #endif // MSGPACK_GCC_ATOMIC_H 26 | -------------------------------------------------------------------------------- /inc/msgpack/pack_define.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack unpacking routine template 3 | * 4 | * Copyright (C) 2008-2010 FURUHASHI Sadayuki 5 | * 6 | * Distributed under the Boost Software License, Version 1.0. 7 | * (See accompanying file LICENSE_1_0.txt or copy at 8 | * http://www.boost.org/LICENSE_1_0.txt) 9 | */ 10 | #ifndef MSGPACK_PACK_DEFINE_H 11 | #define MSGPACK_PACK_DEFINE_H 12 | 13 | #include "msgpack/sysdep.h" 14 | #include 15 | #include 16 | 17 | #endif /* msgpack/pack_define.h */ 18 | 19 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/_cassert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2011-2012 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL__CASSERT_H 9 | #define MSGPACK_PREDEF_DETAIL__CASSERT_H 10 | 11 | #if defined(__cplusplus) 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2011-2012 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL__EXCEPTION_H 9 | #define MSGPACK_PREDEF_DETAIL__EXCEPTION_H 10 | 11 | #if defined(__cplusplus) 12 | #include 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/comp_detected.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2014 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL_COMP_DETECTED 9 | #define MSGPACK_PREDEF_DETAIL_COMP_DETECTED 1 10 | #endif 11 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/endian_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2013 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL_ENDIAN_COMPAT_H 9 | #define MSGPACK_PREDEF_DETAIL_ENDIAN_COMPAT_H 10 | 11 | #include 12 | 13 | #if MSGPACK_ENDIAN_BIG_BYTE 14 | # define MSGPACK_BIG_ENDIAN 15 | # define MSGPACK_BYTE_ORDER 4321 16 | #endif 17 | #if MSGPACK_ENDIAN_LITTLE_BYTE 18 | # define MSGPACK_LITTLE_ENDIAN 19 | # define MSGPACK_BYTE_ORDER 1234 20 | #endif 21 | #if MSGPACK_ENDIAN_LITTLE_WORD 22 | # define MSGPACK_PDP_ENDIAN 23 | # define MSGPACK_BYTE_ORDER 2134 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/os_detected.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2013 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL_OS_DETECTED 9 | #define MSGPACK_PREDEF_DETAIL_OS_DETECTED 1 10 | #endif 11 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/platform_detected.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2014 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL_PLAT_DETECTED 9 | #define MSGPACK_PREDEF_DETAIL_PLAT_DETECTED 1 10 | #endif 11 | -------------------------------------------------------------------------------- /inc/msgpack/predef/detail/test.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2011-2012 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_DETAIL_TEST_H 9 | #define MSGPACK_PREDEF_DETAIL_TEST_H 10 | 11 | #if !defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) 12 | 13 | #define MSGPACK_PREDEF_DECLARE_TEST(x,s) 14 | 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /inc/msgpack/predef/hardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Charly Chevalier 2015 3 | Copyright Joel Falcou 2015 4 | Distributed under the Boost Software License, Version 1.0. 5 | (See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | 9 | #if !defined(MSGPACK_PREDEF_HARDWARE_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) 10 | #ifndef MSGPACK_PREDEF_HARDWARE_H 11 | #define MSGPACK_PREDEF_HARDWARE_H 12 | #endif 13 | 14 | #include 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /inc/msgpack/predef/language.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2011-2015 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #if !defined(MSGPACK_PREDEF_LANGUAGE_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) 9 | #ifndef MSGPACK_PREDEF_LANGUAGE_H 10 | #define MSGPACK_PREDEF_LANGUAGE_H 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /inc/msgpack/predef/library.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2008-2015 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #if !defined(MSGPACK_PREDEF_LIBRARY_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) 9 | #ifndef MSGPACK_PREDEF_LIBRARY_H 10 | #define MSGPACK_PREDEF_LIBRARY_H 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /inc/msgpack/predef/library/c.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2008-2015 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #if !defined(MSGPACK_PREDEF_LIBRARY_C_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) 9 | #ifndef MSGPACK_PREDEF_LIBRARY_C_H 10 | #define MSGPACK_PREDEF_LIBRARY_C_H 11 | #endif 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /inc/msgpack/predef/library/c/_prefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2008-2013 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_LIBRARY_C__PREFIX_H 9 | #define MSGPACK_PREDEF_LIBRARY_C__PREFIX_H 10 | 11 | #include 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /inc/msgpack/predef/library/std/_prefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2008-2013 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | #ifndef MSGPACK_PREDEF_LIBRARY_STD__PREFIX_H 8 | #define MSGPACK_PREDEF_LIBRARY_STD__PREFIX_H 9 | 10 | /* 11 | We need to include an STD header to gives us the context 12 | of which library we are using. The "smallest" code-wise header 13 | seems to be . Boost uses but as far 14 | as I can tell (RR) it's not a stand-alone header in most 15 | implementations. Using also has the benefit of 16 | being available in EC++, so we get a chance to make this work 17 | for embedded users. And since it's not a header impacted by TR1 18 | there's no magic needed for inclusion in the face of the 19 | Boost.TR1 library. 20 | */ 21 | #include 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /inc/msgpack/predef/other.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2013-2015 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #if !defined(MSGPACK_PREDEF_OTHER_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) 9 | #ifndef MSGPACK_PREDEF_OTHER_H 10 | #define MSGPACK_PREDEF_OTHER_H 11 | #endif 12 | 13 | #include 14 | /*#include */ 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /inc/msgpack/predef/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Rene Rivera 2015-2016 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #ifndef MSGPACK_PREDEF_VERSION_H 9 | #define MSGPACK_PREDEF_VERSION_H 10 | 11 | #include 12 | 13 | #define MSGPACK_PREDEF_VERSION MSGPACK_VERSION_NUMBER(1,8,0) 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /inc/msgpack/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C utilities 3 | * 4 | * Copyright (C) 2014 FURUHASHI Sadayuki 5 | * 6 | * Distributed under the Boost Software License, Version 1.0. 7 | * (See accompanying file LICENSE_1_0.txt or copy at 8 | * http://www.boost.org/LICENSE_1_0.txt) 9 | */ 10 | #ifndef MSGPACK_UTIL_H 11 | #define MSGPACK_UTIL_H 12 | 13 | #define MSGPACK_UNUSED(a) (void)(a) 14 | 15 | #endif /* MSGPACK_UTIL_H */ 16 | -------------------------------------------------------------------------------- /inc/msgpack/version.c: -------------------------------------------------------------------------------- 1 | #include "msgpack.h" 2 | 3 | const char* msgpack_version(void) 4 | { 5 | return MSGPACK_VERSION; 6 | } 7 | 8 | int msgpack_version_major(void) 9 | { 10 | return MSGPACK_VERSION_MAJOR; 11 | } 12 | 13 | int msgpack_version_minor(void) 14 | { 15 | return MSGPACK_VERSION_MINOR; 16 | } 17 | 18 | int msgpack_version_revision(void) 19 | { 20 | return MSGPACK_VERSION_REVISION; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /inc/msgpack/version_master.h: -------------------------------------------------------------------------------- 1 | #define MSGPACK_VERSION_MAJOR 3 2 | #define MSGPACK_VERSION_MINOR 2 3 | #define MSGPACK_VERSION_REVISION 1 4 | -------------------------------------------------------------------------------- /inc/ti/access.h: -------------------------------------------------------------------------------- 1 | /* 2 | * access.h 3 | */ 4 | #ifndef TI_ACCESS_H_ 5 | #define TI_ACCESS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_access_grant(vec_t ** access, ti_user_t * user, uint64_t mask); 12 | void ti_access_revoke(vec_t * access, ti_user_t * user, uint64_t mask); 13 | _Bool ti_access_check(const vec_t * access, ti_user_t * user, uint64_t mask); 14 | _Bool ti_access_check_or(const vec_t * access, ti_user_t * user, uint64_t mask); 15 | int ti_access_check_err( 16 | const vec_t * access, 17 | ti_user_t * user, 18 | uint64_t mask, 19 | ex_t * e); 20 | int ti_access_more_check( 21 | const vec_t * access, 22 | ti_user_t * o, 23 | ti_user_t * n, 24 | ex_t * e); 25 | int ti_access_check_or_err( 26 | const vec_t * access, 27 | ti_user_t * user, 28 | uint64_t mask, 29 | ex_t * e); 30 | 31 | #endif /* TI_ACCESS_H_ */ 32 | -------------------------------------------------------------------------------- /inc/ti/archfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/archfile.h 3 | */ 4 | #ifndef TI_ARCHFILE_H_ 5 | #define TI_ARCHFILE_H_ 6 | 7 | typedef struct ti_archfile_s ti_archfile_t; 8 | 9 | #include 10 | 11 | ti_archfile_t * ti_archfile_upsert(const char * path, const char * fn); 12 | ti_archfile_t * ti_archfile_from_change_ids( 13 | const char * path, 14 | uint64_t first, 15 | uint64_t last); 16 | void ti_archfile_destroy(ti_archfile_t * archfile); 17 | ti_archfile_t * ti_archfile_get(uint64_t first, uint64_t last); 18 | _Bool ti_archfile_is_valid_fn(const char * fn); 19 | 20 | 21 | struct ti_archfile_s 22 | { 23 | uint64_t first; /* inclusive */ 24 | uint64_t last; /* inclusive */ 25 | char * fn; 26 | }; 27 | 28 | #endif /* TI_ARCHFILE_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/archive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/archive.h 3 | */ 4 | #ifndef TI_ARCHIVE_H_ 5 | #define TI_ARCHIVE_H_ 6 | 7 | typedef struct ti_archive_s ti_archive_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct ti_archive_s 15 | { 16 | char * path; 17 | queue_t * queue; /* ordered ti_cpkg_t on change_id */ 18 | vec_t * archfiles; /* ti_archfile_t, unordered */ 19 | }; 20 | 21 | int ti_archive_create(void); 22 | void ti_archive_destroy(void); 23 | int ti_archive_rmdir(void); 24 | int ti_archive_init(void); 25 | int ti_archive_load(void); 26 | int ti_archive_push(ti_cpkg_t * cpkg); 27 | int ti_archive_to_disk(void); 28 | uint64_t ti_archive_get_first_change_id(void); 29 | ti_cpkg_t * ti_archive_get_change(uint64_t change_id); 30 | 31 | 32 | #endif /* TI_ARCHIVE_H_ */ 33 | -------------------------------------------------------------------------------- /inc/ti/args.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/args.h 3 | */ 4 | #ifndef TI_ARGS_H_ 5 | #define TI_ARGS_H_ 6 | 7 | typedef struct ti_args_s ti_args_t; 8 | 9 | #include 10 | 11 | int ti_args_create(void); 12 | void ti_args_destroy(void); 13 | int ti_args_parse(int argc, char *argv[]); 14 | 15 | struct ti_args_s 16 | { 17 | /* true/false props */ 18 | int32_t deploy; 19 | int32_t force; 20 | int32_t init; 21 | int32_t log_colorized; 22 | int32_t rebuild; 23 | int32_t forget_nodes; 24 | int32_t yes; 25 | int32_t version; 26 | 27 | /* string props */ 28 | char config[ARGPARSE_MAX_LEN_ARG]; 29 | char log_level[ARGPARSE_MAX_LEN_ARG]; /* can be overwritten at runtime */ 30 | char secret[ARGPARSE_MAX_LEN_ARG]; /* allow only graphic characters */ 31 | }; 32 | 33 | #endif /* TI_ARGS_H_ */ 34 | 35 | 36 | -------------------------------------------------------------------------------- /inc/ti/async.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/async.h 3 | */ 4 | #ifndef TI_ASYNC_H_ 5 | #define TI_ASYNC_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_module_t * ti_async_get_module(void); 12 | void ti_async_init(void); 13 | 14 | #endif /* TI_EXT_ASYNC_H_ */ 15 | -------------------------------------------------------------------------------- /inc/ti/build.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/build.h 3 | */ 4 | #ifndef TI_BUILD_H_ 5 | #define TI_BUILD_H_ 6 | 7 | enum 8 | { 9 | TI_BUILD_WAITING, 10 | TI_BUILD_REQ_SETUP, 11 | }; 12 | 13 | typedef struct ti_build_s ti_build_t; 14 | 15 | #include 16 | #include 17 | 18 | int ti_build_create(void); 19 | void ti_build_destroy(void); 20 | int ti_build_setup( 21 | uint32_t this_node_id, 22 | uint32_t from_node_id, 23 | uint8_t from_node_status, 24 | uint8_t from_node_zone, 25 | uint16_t from_node_syntax_ver, 26 | uint16_t from_node_port, 27 | ti_stream_t * stream); 28 | 29 | struct ti_build_s 30 | { 31 | uint32_t this_node_id; 32 | uint32_t from_node_id; 33 | uint8_t status; 34 | uint8_t from_node_status; 35 | uint8_t from_node_zone; 36 | uint16_t from_node_syntax_ver; 37 | uint16_t from_node_port; 38 | }; 39 | 40 | #endif /* TI_BUILD_H */ 41 | -------------------------------------------------------------------------------- /inc/ti/changes.inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/changes.inline.h 3 | */ 4 | #ifndef TI_CHANGES_INLINE_H_ 5 | #define TI_CHANGES_INLINE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* 12 | * The dropped list must take a reference because the thing might increase a 13 | * reference within a change, and then drop again. When that happens, the 14 | * thing will be added to the dropped list twice, so when destroying the 15 | * list we only need to destroy the last one. 16 | */ 17 | static inline _Bool ti_changes_cache_dropped_thing(ti_thing_t * thing) 18 | { 19 | _Bool keep = changes_.keep_dropped && !vec_push(&changes_.dropped, thing); 20 | if (keep) 21 | ti_incref(thing); 22 | return keep; 23 | } 24 | 25 | #endif /* TI_CHANGES_INLINE_H_*/ 26 | -------------------------------------------------------------------------------- /inc/ti/clients.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clients.h 3 | */ 4 | #ifndef TI_CLIENTS_H_ 5 | #define TI_CLIENTS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | typedef struct ti_clients_s ti_clients_t; 13 | 14 | int ti_clients_create(void); 15 | void ti_clients_destroy(void); 16 | int ti_clients_listen(void); 17 | void ti_clients_write_rpkg(ti_rpkg_t * rpkg); 18 | _Bool ti_clients_is_fwd_req(ti_req_t * req); 19 | void ti_clients_pkg_cb(ti_stream_t * stream, ti_pkg_t * pkg); 20 | 21 | struct ti_clients_s 22 | { 23 | uv_tcp_t tcp; 24 | uv_pipe_t pipe; 25 | }; 26 | 27 | #endif /* TI_CLIENTS_H_ */ 28 | -------------------------------------------------------------------------------- /inc/ti/condition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/condition.h 3 | */ 4 | #ifndef TI_CONDITION_H_ 5 | #define TI_CONDITION_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int ti_condition_field_info_init( 15 | ti_field_t * field, 16 | const char * str, 17 | size_t n, 18 | ex_t * e); 19 | int ti_condition_field_re_init( 20 | ti_field_t * field, 21 | const char * str, 22 | size_t n, 23 | ex_t * e); 24 | int ti_condition_field_rel_init( 25 | ti_field_t * field, 26 | ti_field_t * ofield, 27 | ex_t * e); 28 | int ti_condition_init_enum(ti_field_t * field, ti_member_t * member, ex_t * e); 29 | 30 | void ti_condition_destroy(ti_condition_via_t condition, uint16_t spec); 31 | 32 | #endif /* TI_CONDITION_H_ */ 33 | -------------------------------------------------------------------------------- /inc/ti/connect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/connect.h 3 | */ 4 | #ifndef TI_CONNECT_H_ 5 | #define TI_CONNECT_H_ 6 | 7 | typedef struct ti_connect_s ti_connect_t; 8 | 9 | #include 10 | 11 | int ti_connect_create(void); 12 | int ti_connect_start(void); 13 | void ti_connect_stop(void); 14 | void ti_connect_force_sync(void); 15 | 16 | struct ti_connect_s 17 | { 18 | _Bool is_started; 19 | _Bool _sync_changes; /* set to `true` after changes are processed */ 20 | uint32_t n_loops; /* count number of loops */ 21 | uv_timer_t * timer; 22 | }; 23 | 24 | #endif /* TI_CONNECT_H_ */ 25 | -------------------------------------------------------------------------------- /inc/ti/cpkg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/cpkg.h 3 | */ 4 | #ifndef TI_CPKG_H_ 5 | #define TI_CPKG_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | ti_cpkg_t * ti_cpkg_create(ti_pkg_t * pkg, uint64_t change_id); 13 | ti_cpkg_t * ti_cpkg_initial(void); 14 | ti_cpkg_t * ti_cpkg_from_pkg(ti_pkg_t * pkg); 15 | 16 | #endif /* TI_CPKG_H_ */ 17 | -------------------------------------------------------------------------------- /inc/ti/cpkg.inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/cpkg.inline.h 3 | */ 4 | #ifndef TI_EPKG_INLINE_H_ 5 | #define TI_EPKG_INLINE_H_ 6 | 7 | #include 8 | #include 9 | 10 | static inline void ti_cpkg_drop(ti_cpkg_t * cpkg) 11 | { 12 | ti_rpkg_drop((ti_rpkg_t *) cpkg); 13 | } 14 | 15 | #endif /* TI_EPKG_INLINE_H_ */ 16 | -------------------------------------------------------------------------------- /inc/ti/cpkg.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/cpkg.t.h 3 | */ 4 | #ifndef TI_CPKG_T_H_ 5 | #define TI_CPKG_T_H_ 6 | 7 | typedef struct ti_cpkg_s ti_cpkg_t; 8 | 9 | #include 10 | #include 11 | 12 | enum 13 | { 14 | TI_CPKG_FLAG_ALLOW_GAP = 1<<0 15 | }; 16 | 17 | struct ti_cpkg_s 18 | { 19 | uint32_t ref; 20 | uint32_t flags; /* required for alignment with ti_rpkg_t */ 21 | ti_pkg_t * pkg; /* must align with ti_rpkg_t */ 22 | uint64_t change_id; 23 | }; 24 | 25 | #endif /* TI_CPKG_T_H_ */ 26 | -------------------------------------------------------------------------------- /inc/ti/ctask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/ctask.h (collection task) 3 | */ 4 | #ifndef TI_CTASK_H_ 5 | #define TI_CTASK_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_ctask_run(ti_thing_t * thing, mp_unp_t * up); 12 | 13 | #endif /* TI_CTASK_H_ */ 14 | -------------------------------------------------------------------------------- /inc/ti/data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/data.h 3 | */ 4 | #ifndef TI_DATA_H_ 5 | #define TI_DATA_H_ 6 | 7 | #include 8 | #include 9 | 10 | typedef struct ti_data_s ti_data_t; 11 | 12 | struct ti_data_s 13 | { 14 | size_t n; 15 | unsigned char data[]; 16 | }; 17 | 18 | static inline void ti_data_init(ti_data_t * data, size_t total_n) 19 | { 20 | data->n = total_n - sizeof(ti_data_t); 21 | } 22 | 23 | #endif /* TI_DATA_H_ */ 24 | -------------------------------------------------------------------------------- /inc/ti/deep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/deep.h 3 | */ 4 | #ifndef TI_DEEP_H_ 5 | #define TI_DEEP_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_deep_from_val(ti_val_t * val, uint8_t * deep, ex_t * e); 12 | 13 | #endif /* TI_DEEP_H_ */ 14 | -------------------------------------------------------------------------------- /inc/ti/dump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/dump.h 3 | */ 4 | #ifndef TI_DUMP_H_ 5 | #define TI_DUMP_H_ 6 | 7 | #include 8 | #include 9 | 10 | ti_raw_t * ti_dump_collection(ti_collection_t * collection); 11 | 12 | #endif /* TI_DUMP_H_ */ 13 | -------------------------------------------------------------------------------- /inc/ti/enums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/enums.h 3 | */ 4 | #ifndef TI_ENUMS_H_ 5 | #define TI_ENUMS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | ti_enums_t * ti_enums_create(ti_collection_t * collection); 17 | void ti_enums_destroy(ti_enums_t * enums); 18 | int ti_enums_add(ti_enums_t * enums, ti_enum_t * enum_); 19 | int ti_enums_rename(ti_enums_t * enums, ti_enum_t * enum_, ti_raw_t * nname); 20 | void ti_enums_del(ti_enums_t * enums, ti_enum_t * enum_, vec_t * vars); 21 | uint16_t ti_enums_get_new_id(ti_enums_t * enums, ex_t * e); 22 | ti_varr_t * ti_enums_info(ti_enums_t * enums); 23 | int ti_enums_to_pk(ti_enums_t * enums, ti_vp_t * vp); 24 | 25 | #endif /* TI_ENUMS_H_ */ 26 | -------------------------------------------------------------------------------- /inc/ti/enums.inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/enums.inline.h 3 | */ 4 | #ifndef TI_ENUMS_INLINE_H_ 5 | #define TI_ENUMS_INLINE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | static inline ti_enum_t * ti_enums_by_strn(ti_enums_t * enums, const char * str, size_t n) 14 | { 15 | return smap_getn(enums->smap, str, n); 16 | } 17 | 18 | static inline ti_enum_t * ti_enums_by_raw(ti_enums_t * enums, ti_raw_t * raw) 19 | { 20 | return smap_getn(enums->smap, (const char *) raw->data, raw->n); 21 | } 22 | 23 | static inline ti_enum_t * ti_enums_by_id(ti_enums_t * enums, uint16_t enum_id) 24 | { 25 | return imap_get(enums->imap, enum_id); 26 | } 27 | 28 | #endif /* TI_ENUMS_INLINE_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/enums.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/enums.t.h 3 | */ 4 | #ifndef TI_ENUMS_T_H_ 5 | #define TI_ENUMS_T_H_ 6 | 7 | typedef struct ti_enums_s ti_enums_t; 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | struct ti_enums_s 14 | { 15 | imap_t * imap; 16 | smap_t * smap; 17 | ti_collection_t * collection; 18 | }; 19 | 20 | #endif /* TI_ENUMS_T_H_ */ 21 | -------------------------------------------------------------------------------- /inc/ti/evars.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/evars.h 3 | */ 4 | #ifndef TI_EVARS_H_ 5 | #define TI_EVARS_H_ 6 | 7 | void ti_evars_arg_parse(void); 8 | void ti_evars_cfg_parse(void); 9 | 10 | #endif /* TI_EVARS_H_ */ 11 | -------------------------------------------------------------------------------- /inc/ti/export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/export.h 3 | */ 4 | #ifndef TI_EXPORT_H_ 5 | #define TI_EXPORT_H_ 6 | 7 | #include 8 | #include 9 | 10 | ti_raw_t * ti_export_collection(ti_collection_t * collection); 11 | 12 | #endif /* TI_EXPORT_H_ */ 13 | -------------------------------------------------------------------------------- /inc/ti/flags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/flags.h 3 | */ 4 | #ifndef TI_FLAGS_H_ 5 | #define TI_FLAGS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | #define TI_FLAGS_QUERY_MASK 0x1f 13 | 14 | /* flags must fit with `TI_QUERY_FLAG` defined in query.t.h */ 15 | enum 16 | { 17 | TI_FLAGS_NO_IDS=1<<5, /* return no ID's, must be 32 (1<<5) as it maps 18 | * with TI_FIELD_FLAG_NO_IDS */ 19 | }; 20 | 21 | int ti_flags_set_from_val(ti_val_t * val, uint8_t * flags, ex_t * e); 22 | 23 | #endif /* TI_FLAGS_H_ */ 24 | -------------------------------------------------------------------------------- /inc/ti/fn/fnat.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_at(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_tz_t * tz = fn_default_tz(query); 7 | ti_vtask_t * vtask; 8 | 9 | if (!ti_val_is_task(query->rval)) 10 | return fn_call_try("at", query, nd, e); 11 | 12 | vtask = (ti_vtask_t *) query->rval; 13 | 14 | if (fn_nargs("at", DOC_TASK_AT, 0, nargs, e)) 15 | return e->nr; 16 | 17 | if (vtask->run_at) 18 | { 19 | ti_datetime_t * dt = ti_datetime_from_u64(vtask->run_at, tz); 20 | query->rval = (ti_val_t *) dt; 21 | if (!dt) 22 | ex_set_mem(e); 23 | } 24 | else 25 | query->rval = (ti_val_t *) ti_nil_get(); 26 | 27 | ti_vtask_unsafe_drop(vtask); 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnbackupinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_backup_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | int64_t backup_id; 6 | const int nargs = fn_get_nargs(nd); 7 | 8 | if (fn_not_node_scope("backup_info", query, e) || 9 | fn_nargs("backup_info", DOC_BACKUP_INFO, 1, nargs, e) || 10 | ti_do_statement(query, nd->children, e) || 11 | fn_arg_int("backup_info", DOC_BACKUP_INFO, 1, query->rval, e)) 12 | return e->nr; 13 | 14 | backup_id = VINT(query->rval); 15 | 16 | if (backup_id < 0) 17 | { 18 | ex_set(e, EX_VALUE_ERROR, 19 | "function `backup_info` expects argument 1 to be a " 20 | "positive integer value"DOC_BACKUP_INFO); 21 | return e->nr; 22 | } 23 | 24 | ti_val_unsafe_drop(query->rval); 25 | query->rval = ti_backups_backup_as_mpval((uint64_t) backup_id, e); 26 | 27 | return e->nr; 28 | } 29 | -------------------------------------------------------------------------------- /inc/ti/fn/fnbackupsinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_backups_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_node_scope("backups_info", query, e) || 8 | fn_nargs("backups_info", DOC_BACKUPS_INFO, 0, nargs, e)) 9 | return e->nr; 10 | 11 | query->rval = (ti_val_t *) ti_backups_info(); 12 | if (!query->rval) 13 | ex_set_mem(e); 14 | 15 | return e->nr; 16 | } 17 | -------------------------------------------------------------------------------- /inc/ti/fn/fnbackupsok.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_backups_ok(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | /* feature request, issue #341 */ 6 | const int nargs = fn_get_nargs(nd); 7 | 8 | if (fn_not_node_scope("backups_ok", query, e) || 9 | fn_nargs("backups_ok", DOC_BACKUPS_OK, 0, nargs, e)) 10 | return e->nr; 11 | 12 | query->rval = (ti_val_t *) ti_vbool_get(ti_backups_ok()); 13 | return e->nr; 14 | } 15 | -------------------------------------------------------------------------------- /inc/ti/fn/fnbool.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_bool(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool tobool; 7 | 8 | if (fn_nargs_max("bool", DOC_BOOL, 1, nargs, e)) 9 | return e->nr; 10 | 11 | if (nargs == 0) 12 | { 13 | assert(query->rval == NULL); 14 | query->rval = (ti_val_t *) ti_vbool_get(false); 15 | return 0; 16 | } 17 | 18 | if (ti_do_statement(query, nd->children, e)) 19 | return e->nr; 20 | 21 | tobool = ti_val_as_bool(query->rval); 22 | ti_val_unsafe_drop(query->rval); 23 | query->rval = (ti_val_t *) ti_vbool_get(tobool); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /inc/ti/fn/fnbytes.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_bytes(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("bytes", DOC_BYTES, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (nargs == 0) 11 | { 12 | query->rval = (ti_val_t *) ti_val_empty_bin(); 13 | return e->nr; 14 | } 15 | 16 | if (ti_do_statement(query, nd->children, e)) 17 | return e->nr; 18 | 19 | return ti_val_convert_to_bytes(&query->rval, e); 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fncall.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static inline int do__f_call(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | return fn_call(query, nd, e); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /inc/ti/fn/fnchangeid.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_change_id(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs("change_id", DOC_CHANGE_ID, 0, nargs, e)) 8 | return e->nr; 9 | 10 | query->rval = query->change 11 | ? (ti_val_t *) ti_vint_create((int64_t) query->change->id) 12 | : (ti_val_t *) ti_nil_get(); 13 | 14 | if (!query->rval) 15 | ex_set_mem(e); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fncode.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_code(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_verror_t * err; 7 | 8 | if (!ti_val_is_error(query->rval)) 9 | return fn_call_try("code", query, nd, e); 10 | 11 | if (fn_nargs("code", DOC_ERROR_CODE, 0, nargs, e)) 12 | return e->nr; 13 | 14 | err = (ti_verror_t *) query->rval; 15 | 16 | query->rval = (ti_val_t *) ti_vint_create(err->code); 17 | if (!query->rval) 18 | ex_set_mem(e); 19 | 20 | ti_val_unsafe_drop((ti_val_t *) err); 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fncollectionsinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_collections_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_user_t * user = query->user; 7 | 8 | if (fn_not_thingsdb_scope("collections_info", query, e) || 9 | fn_nargs("collections_info", DOC_COLLECTIONS_INFO, 0, nargs, e)) 10 | return e->nr; 11 | 12 | if (ti_access_check(ti.access_thingsdb, user, TI_AUTH_CHANGE)) 13 | { 14 | /* 15 | * Only if the user has no `CHANGE` permissions in the thingsdb scope, 16 | * then only collection info for collections where the user has at 17 | * least read permissions are returned. 18 | */ 19 | user = NULL; 20 | } 21 | 22 | query->rval = (ti_val_t *) ti_collections_info(user); 23 | if (!query->rval) 24 | ex_set_mem(e); 25 | 26 | return e->nr; 27 | } 28 | -------------------------------------------------------------------------------- /inc/ti/fn/fncontains.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_contains(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | _Bool contains; 8 | 9 | if (!ti_val_is_str(query->rval)) 10 | return fn_call_try("contains", query, nd, e); 11 | 12 | if (fn_nargs("contains", DOC_STR_CONTAINS, 1, nargs, e)) 13 | return e->nr; 14 | 15 | raw = (ti_raw_t *) query->rval; 16 | query->rval = NULL; 17 | 18 | if (ti_do_statement(query, nd->children, e) || 19 | fn_arg_str("contains", DOC_STR_CONTAINS, 1, query->rval, e)) 20 | goto failed; 21 | 22 | contains = ti_raw_contains(raw, (ti_raw_t *) query->rval); 23 | ti_val_unsafe_drop(query->rval); 24 | query->rval = (ti_val_t *) ti_vbool_get(contains); 25 | 26 | failed: 27 | ti_val_unsafe_drop((ti_val_t *) raw); 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fncounters.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_counters(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | if (fn_not_node_scope("counters", query, e) || 7 | fn_nargs("counters", DOC_COUNTERS, 0, nargs, e)) 8 | return e->nr; 9 | 10 | query->rval = ti_counters_as_mpval(); 11 | if (!query->rval) 12 | ex_set_mem(e); 13 | 14 | return e->nr; 15 | } 16 | -------------------------------------------------------------------------------- /inc/ti/fn/fndeep.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_deep(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("deep", DOC_DEEP, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (nargs == 1) 11 | { 12 | return ti_do_statement(query, nd->children, e) 13 | ? e->nr 14 | : ti_deep_from_val(query->rval, &query->qbind.deep, e); 15 | } 16 | 17 | /* always success since 0..127 is loaded from the stack */ 18 | query->rval = (ti_val_t *) ti_vint_create((int64_t) query->qbind.deep); 19 | return e->nr; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fndelexpired.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_del_expired(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | uint64_t after_ts; 7 | ti_task_t * task; 8 | 9 | if (fn_not_thingsdb_scope("del_expired", query, e) || 10 | ti_access_check_err( 11 | ti.access_thingsdb, 12 | query->user, TI_AUTH_GRANT, e) || 13 | fn_nargs("del_expired", DOC_DEL_EXPIRED, 0, nargs, e)) 14 | return e->nr; 15 | 16 | after_ts = util_now_usec(); 17 | 18 | task = ti_task_get_task(query->change, ti.thing0); 19 | if (!task || ti_task_add_del_expired(task, after_ts)) 20 | ex_set_mem(e); /* task cleanup is not required */ 21 | else 22 | ti_users_del_expired(after_ts); 23 | 24 | query->rval = (ti_val_t *) ti_nil_get(); 25 | return e->nr; 26 | } 27 | -------------------------------------------------------------------------------- /inc/ti/fn/fndoc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_doc(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * doc; 7 | 8 | if (!ti_val_is_closure(query->rval)) 9 | return fn_call_try("doc", query, nd, e); 10 | 11 | if (fn_nargs("doc", DOC_CLOSURE_DOC, 0, nargs, e)) 12 | return e->nr; 13 | 14 | doc = ti_closure_doc((ti_closure_t *) query->rval); 15 | 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = (ti_val_t *) doc; 18 | 19 | return e->nr; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnendswith.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_ends_with(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | _Bool ends_with; 8 | 9 | if (!ti_val_is_str(query->rval)) 10 | return fn_call_try("ends_with", query, nd, e); 11 | 12 | if (fn_nargs("ends_with", DOC_STR_ENDS_WITH, 1, nargs, e)) 13 | return e->nr; 14 | 15 | raw = (ti_raw_t *) query->rval; 16 | query->rval = NULL; 17 | 18 | if (ti_do_statement(query, nd->children, e) || 19 | fn_arg_str("ends_with", DOC_STR_ENDS_WITH, 1, query->rval, e)) 20 | goto failed; 21 | 22 | ends_with = ti_raw_endswith(raw, (ti_raw_t *) query->rval); 23 | ti_val_unsafe_drop(query->rval); 24 | query->rval = (ti_val_t *) ti_vbool_get(ends_with); 25 | 26 | failed: 27 | ti_val_unsafe_drop((ti_val_t *) raw); 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnenuminfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_enum_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_enum_t * enum_; 7 | 8 | if (fn_not_collection_scope("enum_info", query, e) || 9 | fn_nargs("enum_info", DOC_ENUM_INFO, 1, nargs, e) || 10 | ti_do_statement(query, nd->children, e) || 11 | fn_arg_str("enum_info", DOC_ENUM_INFO, 1, query->rval, e)) 12 | return e->nr; 13 | 14 | enum_ = ti_enums_by_raw(query->collection->enums, (ti_raw_t *) query->rval); 15 | if (!enum_) 16 | return ti_raw_err_not_found((ti_raw_t *) query->rval, "enum", e); 17 | 18 | ti_val_unsafe_drop(query->rval); 19 | query->rval = ti_enum_as_mpval(enum_); 20 | if (!query->rval) 21 | ex_set_mem(e); 22 | 23 | return e->nr; 24 | } 25 | -------------------------------------------------------------------------------- /inc/ti/fn/fnenumsinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_enums_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_collection_scope("enums_info", query, e) || 8 | fn_nargs("enums_info", DOC_ENUMS_INFO, 0, nargs, e)) 9 | return e->nr; 10 | 11 | query->rval = (ti_val_t *) ti_enums_info(query->collection->enums); 12 | if (!query->rval) 13 | ex_set_mem(e); 14 | 15 | return e->nr; 16 | } 17 | -------------------------------------------------------------------------------- /inc/ti/fn/fnexp.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_exp(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | double d; 7 | 8 | if (fn_nargs("exp", DOC_MATH_EXP, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e) || 10 | fn_arg_number("exp", DOC_MATH_EXP, 1, query->rval, e)) 11 | return e->nr; 12 | 13 | if (query->rval->tp == TI_VAL_INT) 14 | { 15 | int64_t i = VINT(query->rval); 16 | d = (double) i; 17 | } 18 | else 19 | { 20 | d = VFLOAT(query->rval); 21 | if (isnan(d)) 22 | return e->nr; 23 | } 24 | d = exp(d); 25 | 26 | ti_val_unsafe_drop(query->rval); 27 | query->rval = (ti_val_t *) ti_vfloat_create(d); 28 | if (!query->rval) 29 | ex_set_mem(e); 30 | 31 | return e->nr; 32 | } 33 | -------------------------------------------------------------------------------- /inc/ti/fn/fnfirst.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_first(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_varr_t * varr; 7 | 8 | if (!ti_val_is_array(query->rval)) 9 | return fn_call_try("first", query, nd, e); 10 | 11 | if (fn_nargs_max("first", DOC_LIST_FIRST, 1, nargs, e)) 12 | return e->nr; 13 | 14 | varr = (ti_varr_t *) query->rval; 15 | if (varr->vec->n) 16 | { 17 | query->rval = VEC_get(varr->vec, 0); 18 | ti_incref(query->rval); 19 | goto done; 20 | } 21 | 22 | if (nargs == 0) 23 | { 24 | ex_set(e, EX_LOOKUP_ERROR, "no first item in an empty list"); 25 | return e->nr; 26 | } 27 | 28 | query->rval = NULL; 29 | (void) ti_do_statement(query, nd->children, e); 30 | 31 | done: 32 | ti_val_unsafe_drop((ti_val_t *) varr); 33 | return e->nr; 34 | } 35 | -------------------------------------------------------------------------------- /inc/ti/fn/fnfloat.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_float(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | if (fn_nargs_max("float", DOC_FLOAT, 1, nargs, e)) 7 | return e->nr; 8 | 9 | if (nargs == 0) 10 | { 11 | assert(query->rval == NULL); 12 | query->rval = (ti_val_t *) ti_vfloat_create(0.0); 13 | return e->nr; 14 | } 15 | 16 | if (ti_do_statement(query, nd->children, e)) 17 | return e->nr; 18 | 19 | return ti_val_convert_to_float(&query->rval, e); 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnformat.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_format(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_datetime_t * dt; 7 | ti_raw_t * fmt; 8 | 9 | if (!ti_val_is_datetime(query->rval)) 10 | return fn_call_try("format", query, nd, e); 11 | 12 | if (fn_nargs("format", DOC_DATETIME_FORMAT, 1, nargs, e)) 13 | return e->nr; 14 | 15 | dt = (ti_datetime_t *) query->rval; 16 | query->rval = NULL; 17 | 18 | if (ti_do_statement(query, nd->children, e) || 19 | fn_arg_str("format", DOC_DATETIME_FORMAT, 1, query->rval, e)) 20 | goto fail; 21 | 22 | fmt = (ti_raw_t *) query->rval; 23 | query->rval = (ti_val_t *) ti_datetime_to_str_fmt(dt, fmt, e); 24 | ti_val_unsafe_drop((ti_val_t *) fmt); 25 | 26 | fail: 27 | ti_val_unsafe_drop((ti_val_t *) dt); 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnhascollection.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_has_collection(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_thingsdb_scope("has_collection", query, e) || 8 | fn_nargs("has_collection", DOC_HAS_COLLECTION, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | (void) ti_collections_get_by_val(query->rval, e); 13 | if (e->nr == EX_TYPE_ERROR) 14 | return e->nr; 15 | 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = (ti_val_t *) ti_vbool_get(e->nr == 0); 18 | 19 | ex_clear(e); 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnhasenum.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_has_enum(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | ti_raw_t * rname; 6 | _Bool has_enum; 7 | const int nargs = fn_get_nargs(nd); 8 | 9 | if (fn_not_collection_scope("has_enum", query, e) || 10 | fn_nargs("has_enum", DOC_HAS_ENUM, 1, nargs, e) || 11 | ti_do_statement(query, nd->children, e) || 12 | fn_arg_str("has_enum", DOC_HAS_ENUM, 1, query->rval, e)) 13 | return e->nr; 14 | 15 | rname = (ti_raw_t *) query->rval; 16 | 17 | has_enum = !!ti_enums_by_raw(query->collection->enums, rname); 18 | 19 | ti_val_unsafe_drop(query->rval); 20 | query->rval = (ti_val_t *) ti_vbool_get(has_enum); 21 | 22 | return e->nr; 23 | } 24 | -------------------------------------------------------------------------------- /inc/ti/fn/fnhasmodule.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_has_module(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool has_module; 7 | 8 | if (fn_nargs("has_module", DOC_HAS_MODULE, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e) || 10 | fn_arg_str("has_module", DOC_HAS_MODULE, 1, query->rval, e)) 11 | return e->nr; 12 | 13 | has_module = !!ti_modules_by_raw((ti_raw_t *) query->rval); 14 | 15 | ti_val_unsafe_drop(query->rval); 16 | query->rval = (ti_val_t *) ti_vbool_get(has_module); 17 | 18 | return e->nr; 19 | } 20 | -------------------------------------------------------------------------------- /inc/ti/fn/fnhasprocedure.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_has_procedure(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool has_procedure; 7 | smap_t * procedures = ti_query_procedures(query); 8 | 9 | if (fn_not_thingsdb_or_collection_scope("has_procedure", query, e) || 10 | fn_nargs("has_procedure", DOC_HAS_PROCEDURE, 1, nargs, e) || 11 | ti_do_statement(query, nd->children, e) || 12 | fn_arg_str("has_procedure", DOC_HAS_PROCEDURE, 1, query->rval, e)) 13 | return e->nr; 14 | 15 | has_procedure = !!ti_procedures_by_name( 16 | procedures, 17 | (ti_raw_t *) query->rval); 18 | 19 | ti_val_unsafe_drop(query->rval); 20 | query->rval = (ti_val_t *) ti_vbool_get(has_procedure); 21 | 22 | return e->nr; 23 | } 24 | -------------------------------------------------------------------------------- /inc/ti/fn/fnhastype.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_has_type(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool has_type; 7 | 8 | if (fn_not_collection_scope("has_type", query, e) || 9 | fn_nargs("has_type", DOC_HAS_TYPE, 1, nargs, e) || 10 | ti_do_statement(query, nd->children, e) || 11 | fn_arg_str("has_type", DOC_HAS_TYPE, 1, query->rval, e)) 12 | return e->nr; 13 | 14 | has_type = !!ti_types_by_raw( 15 | query->collection->types, 16 | (ti_raw_t *) query->rval); 17 | 18 | ti_val_unsafe_drop(query->rval); 19 | query->rval = (ti_val_t *) ti_vbool_get(has_type); 20 | 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fnhasuser.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_has_user(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool has_user; 7 | ti_raw_t * uname; 8 | 9 | if (fn_not_thingsdb_scope("has_user", query, e) || 10 | ti_access_check_err( 11 | ti.access_thingsdb, 12 | query->user, TI_AUTH_GRANT, e) || 13 | fn_nargs("has_user", DOC_HAS_USER, 1, nargs, e) || 14 | ti_do_statement(query, nd->children, e) || 15 | fn_arg_str("has_user", DOC_HAS_USER, 1, query->rval, e)) 16 | return e->nr; 17 | 18 | uname = (ti_raw_t *) query->rval; 19 | has_user = !!ti_users_get_by_namestrn( 20 | (const char *) uname->data, 21 | uname->n); 22 | 23 | ti_val_unsafe_drop(query->rval); 24 | query->rval = (ti_val_t *) ti_vbool_get(has_user); 25 | 26 | return e->nr; 27 | } 28 | -------------------------------------------------------------------------------- /inc/ti/fn/fnint.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_int(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("int", DOC_INT, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (nargs == 0) 11 | { 12 | query->rval = (ti_val_t *) ti_vint_create(0); 13 | return e->nr; 14 | } 15 | 16 | if (ti_do_statement(query, nd->children, e)) 17 | return e->nr; 18 | 19 | return ti_val_convert_to_int(&query->rval, e); 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisarray.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_array(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_array; 7 | 8 | if (fn_nargs("is_array", DOC_IS_ARRAY, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_array = ti_val_is_array(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_array); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisascii.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_ascii(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_ascii; 7 | ti_raw_t * raw; 8 | 9 | if (fn_nargs("is_ascii", DOC_IS_ASCII, 1, nargs, e) || 10 | ti_do_statement(query, nd->children, e)) 11 | return e->nr; 12 | 13 | raw = (ti_raw_t *) query->rval; 14 | is_ascii = ti_val_is_str(query->rval) && 15 | strx_is_asciin((const char *) raw->data, raw->n); 16 | 17 | ti_val_unsafe_drop(query->rval); 18 | query->rval = (ti_val_t *) ti_vbool_get(is_ascii); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisbool.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_bool(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_bool; 7 | 8 | if (fn_nargs("is_bool", DOC_IS_BOOL, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_bool = ti_val_is_bool(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_bool); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisbytes.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_bytes(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_bytes; 7 | 8 | if (fn_nargs("is_bytes", DOC_IS_BYTES, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_bytes = ti_val_is_bytes(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_bytes); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisclosure.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_closure(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_closure; 7 | 8 | if (fn_nargs("is_closure", DOC_IS_CLOSURE, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_closure = ti_val_is_closure(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_closure); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisdatetime.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_datetime(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_datetime; 7 | 8 | if (fn_nargs("is_datetime", DOC_IS_DATETIME, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_datetime = ti_val_is_datetime_strict(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_datetime); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisemail.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_email(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_email; 7 | 8 | if (fn_nargs("is_email", DOC_IS_EMAIL, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_email = ti_val_is_str(query->rval) && ti_regex_test( 13 | (ti_regex_t *) ti_val_borrow_re_email(), 14 | (ti_raw_t *) query->rval); 15 | 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = (ti_val_t *) ti_vbool_get(is_email); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisenum.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_enum(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_enum; 7 | 8 | if (fn_nargs("is_enum", DOC_IS_ENUM, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_enum = ti_val_is_member(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_enum); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fniserr.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_err(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_error; 7 | 8 | if (fn_nargs("is_err", DOC_IS_ERR, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_error = ti_val_is_error(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_error); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisfloat.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_float(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_float; 7 | 8 | if (fn_nargs("is_float", DOC_IS_FLOAT, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_float = ti_val_is_float(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_float); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisfuture.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_future(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_future; 7 | 8 | if (fn_nargs("is_future", DOC_IS_FUTURE, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_future = ti_val_is_future(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_future); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisint.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_int(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_isint; 7 | 8 | if (fn_nargs("is_int", DOC_IS_INT, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_isint = ti_val_is_int(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_isint); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnislist.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_list(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_list; 7 | 8 | if (fn_nargs("is_list", DOC_IS_LIST, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_list = ti_val_is_list(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_list); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnismodule.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_module(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_module; 7 | 8 | if (fn_nargs("is_module", DOC_IS_MODULE, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_module = ti_val_is_module(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_module); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnismpdata.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_mpdata(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_mpdata; 7 | 8 | if (fn_nargs("is_mpdata", DOC_IS_MPDATA, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_mpdata = ti_val_is_mpdata(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_mpdata); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisnan.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_nan(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_nan; 7 | 8 | if (fn_nargs("is_nan", DOC_IS_NAN, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | switch (query->rval->tp) 13 | { 14 | case TI_VAL_BOOL: 15 | case TI_VAL_INT: 16 | is_nan = false; 17 | break; 18 | case TI_VAL_FLOAT: 19 | is_nan = isnan(VFLOAT(query->rval)); 20 | break; 21 | default: 22 | is_nan = true; 23 | } 24 | 25 | ti_val_unsafe_drop(query->rval); 26 | query->rval = (ti_val_t *) ti_vbool_get(is_nan); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisnil.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_nil(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_nil; 7 | 8 | if (fn_nargs("is_nil", DOC_IS_NIL, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_nil = ti_val_is_nil(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_nil); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisraw.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_raw(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_raw; 7 | 8 | if (fn_nargs("is_raw", DOC_IS_RAW, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_raw = ti_val_is_raw(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_raw); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisregex.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_regex(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_regex; 7 | 8 | if (fn_nargs("is_regex", DOC_IS_REGEX, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_regex = ti_val_is_regex(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_regex); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisroom.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_room(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_room; 7 | 8 | if (fn_nargs("is_room", DOC_IS_ROOM, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_room = ti_val_is_room(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_room); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisset.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_set(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_set; 7 | 8 | if (fn_nargs("is_set", DOC_IS_SET, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_set = ti_val_is_set(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_set); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisstr.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_str(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_str; 7 | 8 | if (fn_nargs("is_str", DOC_IS_STR, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_str = ti_val_is_str(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_str); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnistask.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_task(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_task; 7 | 8 | if (fn_nargs("is_task", DOC_IS_TASK, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_task = ti_val_is_task(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_task); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnistel.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_tel(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_tel; 7 | 8 | if (fn_nargs("is_tel", DOC_IS_TEL, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_tel = ti_val_is_str(query->rval) && ti_regex_test( 13 | (ti_regex_t *) ti_val_borrow_re_tel(), 14 | (ti_raw_t *) query->rval); 15 | 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = (ti_val_t *) ti_vbool_get(is_tel); 18 | 19 | return e->nr; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisthing.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_thing(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_thing; 7 | 8 | if (fn_nargs("is_thing", DOC_IS_THING, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_thing = ti_val_is_thing(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_thing); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnistimeval.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_timeval(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_timeval; 7 | 8 | if (fn_nargs("is_timeval", DOC_IS_TIMEVAL, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_timeval = ti_val_is_timeval(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_timeval); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnistimezone.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_time_zone(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_time_zone; 7 | ti_raw_t * raw; 8 | 9 | if (fn_nargs("is_time_zone", DOC_IS_TIME_ZONE, 1, nargs, e) || 10 | ti_do_statement(query, nd->children, e)) 11 | return e->nr; 12 | 13 | raw = (ti_raw_t *) query->rval; 14 | is_time_zone = ti_val_is_str(query->rval) && 15 | ti_tz_from_strn((const char *) raw->data, raw->n); 16 | 17 | ti_val_unsafe_drop(query->rval); 18 | query->rval = (ti_val_t *) ti_vbool_get(is_time_zone); 19 | 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnistuple.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_tuple(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_tuple; 7 | 8 | if (fn_nargs("is_tuple", DOC_IS_TUPLE, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_tuple = ti_val_is_tuple(query->rval); 13 | 14 | ti_val_unsafe_drop(query->rval); 15 | query->rval = (ti_val_t *) ti_vbool_get(is_tuple); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisurl.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_url(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_url; 7 | 8 | if (fn_nargs("is_url", DOC_IS_URL, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | is_url = ti_val_is_str(query->rval) && ti_regex_test( 13 | (ti_regex_t *) ti_val_borrow_re_url(), 14 | (ti_raw_t *) query->rval); 15 | 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = (ti_val_t *) ti_vbool_get(is_url); 18 | 19 | return e->nr; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnisutf8.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_is_utf8(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool is_utf8; 7 | ti_raw_t * raw; 8 | 9 | if (fn_nargs("is_utf8", DOC_IS_UTF8, 1, nargs, e) || 10 | ti_do_statement(query, nd->children, e)) 11 | return e->nr; 12 | 13 | raw = (ti_raw_t *) query->rval; 14 | is_utf8 = ti_val_is_str(query->rval) && 15 | strx_is_utf8n((const char *) raw->data, raw->n); 16 | 17 | ti_val_unsafe_drop(query->rval); 18 | query->rval = (ti_val_t *) ti_vbool_get(is_utf8); 19 | 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnlast.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_last(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_varr_t * varr; 7 | 8 | if (!ti_val_is_array(query->rval)) 9 | return fn_call_try("last", query, nd, e); 10 | 11 | if (fn_nargs_max("last", DOC_LIST_LAST, 1, nargs, e)) 12 | return e->nr; 13 | 14 | varr = (ti_varr_t *) query->rval; 15 | if (varr->vec->n) 16 | { 17 | query->rval = VEC_get(varr->vec, varr->vec->n-1); 18 | ti_incref(query->rval); 19 | goto done; 20 | } 21 | 22 | if (nargs == 0) 23 | { 24 | ex_set(e, EX_LOOKUP_ERROR, "no last item in an empty list"); 25 | return e->nr; 26 | } 27 | 28 | query->rval = NULL; 29 | (void) ti_do_statement(query, nd->children, e); 30 | 31 | done: 32 | ti_val_unsafe_drop((ti_val_t *) varr); 33 | return e->nr; 34 | } 35 | -------------------------------------------------------------------------------- /inc/ti/fn/fnlen.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_len(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const char * doc; 6 | const int nargs = fn_get_nargs(nd); 7 | ti_val_t * val; 8 | 9 | doc = doc_len(query->rval); 10 | if (!doc) 11 | return fn_call_try("len", query, nd, e); 12 | 13 | if (fn_nargs("len", doc, 0, nargs, e)) 14 | return e->nr; 15 | 16 | val = query->rval; 17 | query->rval = (ti_val_t *) ti_vint_create((int64_t) ti_val_get_len(val)); 18 | if (!query->rval) 19 | ex_set_mem(e); 20 | 21 | ti_val_unsafe_drop(val); 22 | return e->nr; 23 | } 24 | -------------------------------------------------------------------------------- /inc/ti/fn/fnlist.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_list(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("list", DOC_LIST, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (nargs == 1) 11 | { 12 | return ( 13 | ti_do_statement(query, nd->children, e) || 14 | ti_val_convert_to_array(&query->rval, e) 15 | ); 16 | } 17 | 18 | assert(query->rval == NULL); 19 | query->rval = (ti_val_t *) ti_varr_create(0); 20 | if (!query->rval) 21 | ex_set_mem(e); 22 | 23 | return e->nr; 24 | } 25 | -------------------------------------------------------------------------------- /inc/ti/fn/fnload.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_load(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | mp_unp_t up; 6 | const int nargs = fn_get_nargs(nd); 7 | ti_raw_t * mpdata; 8 | ti_val_t * val; 9 | ti_vup_t vup = { 10 | .isclient = true, 11 | .collection = query->collection, 12 | .up = &up, 13 | }; 14 | 15 | if (!ti_val_is_mpdata(query->rval)) 16 | return fn_call_try("load", query, nd, e); 17 | 18 | if (fn_nargs("load", DOC_MPDATA_LOAD, 0, nargs, e)) 19 | return e->nr; 20 | 21 | mpdata = (ti_raw_t *) query->rval; 22 | mp_unp_init(&up, mpdata->data, mpdata->n); 23 | 24 | val = ti_val_from_vup_e(&vup, e); 25 | ti_val_unsafe_drop(query->rval); 26 | query->rval = val; 27 | 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnlower.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_lower(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | 8 | if (!ti_val_is_str(query->rval)) 9 | return fn_call_try("lower", query, nd, e); 10 | 11 | if (fn_nargs("lower", DOC_STR_LOWER, 0, nargs, e)) 12 | return e->nr; 13 | 14 | raw = (ti_raw_t *) query->rval; 15 | query->rval = (ti_val_t *) ti_str_lower(raw); 16 | if (!query->rval) 17 | ex_set_mem(e); 18 | 19 | ti_val_unsafe_drop((ti_val_t *) raw); 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnmodulesinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_modules_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | int flags = 0; 7 | 8 | if (fn_nargs("modules_info", DOC_MODULES_INFO, 0, nargs, e)) 9 | return e->nr; 10 | 11 | if (!fn_is_not_node_scope(query)) 12 | flags |= TI_MODULE_FLAG_WITH_TASKS|TI_MODULE_FLAG_WITH_RESTARTS; 13 | 14 | if (ti_access_check(ti.access_thingsdb, query->user, TI_AUTH_CHANGE)) 15 | flags |= TI_MODULE_FLAG_WITH_CONF; 16 | 17 | query->rval = (ti_val_t *) ti_modules_info(flags); 18 | if (!query->rval) 19 | ex_set_mem(e); 20 | 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fnmsg.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_msg(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_verror_t * err; 7 | 8 | if (!ti_val_is_error(query->rval)) 9 | return fn_call_try("msg", query, nd, e); 10 | 11 | if (fn_nargs("msg", DOC_ERROR_MSG, 0, nargs, e)) 12 | return e->nr; 13 | 14 | err = (ti_verror_t *) query->rval; 15 | 16 | query->rval = (ti_val_t *) ti_str_create(err->msg, err->msg_n); 17 | if (!query->rval) 18 | ex_set_mem(e); 19 | 20 | ti_val_unsafe_drop((ti_val_t *) err); 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fnnodeinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_node_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_node_scope("node_info", query, e) || 8 | fn_nargs("node_info", DOC_NODE_INFO, 0, nargs, e)) 9 | return e->nr; 10 | 11 | query->rval = ti_this_node_as_mpval(); 12 | if (!query->rval) 13 | ex_set_mem(e); 14 | 15 | return e->nr; 16 | } 17 | -------------------------------------------------------------------------------- /inc/ti/fn/fnnodesinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_nodes_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_node_scope("nodes_info", query, e) || 8 | fn_nargs("nodes_info", DOC_NODES_INFO, 0, nargs, e)) 9 | return e->nr; 10 | 11 | query->rval = (ti_val_t *) ti_nodes_info(); 12 | if (!query->rval) 13 | ex_set_mem(e); 14 | 15 | return e->nr; 16 | } 17 | -------------------------------------------------------------------------------- /inc/ti/fn/fnnow.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_now(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs("now", DOC_NOW, 0, nargs, e)) 8 | return e->nr; 9 | 10 | query->rval = (ti_val_t *) ti_vfloat_create(util_now()); 11 | if (!query->rval) 12 | ex_set_mem(e); 13 | 14 | return e->nr; 15 | } 16 | -------------------------------------------------------------------------------- /inc/ti/fn/fnnse.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_nse(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("nse", DOC_NSE, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (!nargs) 11 | { 12 | query->rval = (ti_val_t *) ti_nil_get(); 13 | return e->nr; 14 | } 15 | 16 | return ti_do_statement(query, nd->children, e); 17 | } 18 | -------------------------------------------------------------------------------- /inc/ti/fn/fnone.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_one(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_vset_t * vset; 7 | ti_val_t * value; 8 | 9 | if (!ti_val_is_set(query->rval)) 10 | return fn_call_try("one", query, nd, e); 11 | 12 | if (fn_nargs("one", DOC_SET_ONE, 0, nargs, e)) 13 | return e->nr; 14 | 15 | vset = (ti_vset_t *) query->rval; 16 | value = imap_one(vset->imap); 17 | 18 | if (!value) 19 | { 20 | ex_set(e, EX_LOOKUP_ERROR, "one from empty set"); 21 | return e->nr; 22 | } 23 | 24 | query->rval = value; 25 | ti_incref(value); 26 | 27 | ti_val_unsafe_drop((ti_val_t *) vset); 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnowner.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_owner(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_vtask_t * vtask; 7 | 8 | if (!ti_val_is_task(query->rval)) 9 | return fn_call_try("owner", query, nd, e); 10 | 11 | vtask = (ti_vtask_t *) query->rval; 12 | 13 | if (ti_vtask_is_nil(vtask, e) || 14 | fn_nargs("owner", DOC_TASK_OWNER, 0, nargs, e)) 15 | return e->nr; 16 | 17 | query->rval = (ti_val_t *) vtask->user->name; 18 | ti_incref(query->rval); 19 | 20 | ti_vtask_unsafe_drop(vtask); 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fnproceduredoc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_procedure_doc(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_procedure_t * procedure; 7 | smap_t * procedures = ti_query_procedures(query); 8 | 9 | if (fn_not_thingsdb_or_collection_scope("procedure_doc", query, e) || 10 | fn_nargs("procedure_doc", DOC_PROCEDURE_DOC, 1, nargs, e) || 11 | ti_do_statement(query, nd->children, e) || 12 | fn_arg_str("procedure_doc", DOC_PROCEDURE_DOC, 1, query->rval, e)) 13 | return e->nr; 14 | 15 | procedure = ti_procedures_by_name(procedures, (ti_raw_t *) query->rval); 16 | if (!procedure) 17 | return ti_raw_err_not_found((ti_raw_t *) query->rval, "procedure", e); 18 | 19 | ti_val_unsafe_drop(query->rval); 20 | 21 | query->rval = (ti_val_t *) ti_closure_doc(procedure->closure); 22 | 23 | return e->nr; 24 | } 25 | -------------------------------------------------------------------------------- /inc/ti/fn/fnproceduresinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_procedures_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | _Bool with_definition; 7 | smap_t * procedures = ti_query_procedures(query); 8 | 9 | if (fn_not_thingsdb_or_collection_scope("procedures_info", query, e) || 10 | fn_nargs("procedures_info", DOC_PROCEDURES_INFO, 0, nargs, e)) 11 | return e->nr; 12 | 13 | with_definition = ti_access_check( 14 | ti_query_access(query), 15 | query->user, 16 | TI_AUTH_CHANGE); 17 | 18 | query->rval = (ti_val_t *) ti_procedures_info(procedures, with_definition); 19 | 20 | if (!query->rval) 21 | ex_set_mem(e); 22 | 23 | return e->nr; 24 | } 25 | -------------------------------------------------------------------------------- /inc/ti/fn/fnrand.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_rand(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs("rand", DOC_RAND, 0, nargs, e)) 8 | return e->nr; 9 | 10 | query->rval = (ti_val_t *) ti_vfloat_create((double) rand() / (RAND_MAX)); 11 | if (!query->rval) 12 | ex_set_mem(e); 13 | 14 | return e->nr; 15 | } 16 | -------------------------------------------------------------------------------- /inc/ti/fn/fnrefs.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_refs(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | uint32_t ref; 7 | 8 | if (fn_nargs("refs", DOC_REFS, 1, nargs, e) || 9 | ti_do_statement(query, nd->children, e)) 10 | return e->nr; 11 | 12 | ref = query->rval->ref; 13 | ti_val_unsafe_drop(query->rval); 14 | 15 | query->rval = (ti_val_t *) ti_vint_create((int64_t) ref); 16 | if (!query->rval) 17 | ex_set_mem(e); 18 | 19 | return e->nr; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnresetcounters.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_reset_counters(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_node_scope("reset_counters", query, e) || 8 | ti_access_check_err(ti.access_node, 9 | query->user, TI_AUTH_CHANGE, e) || 10 | fn_nargs("reset_counters", DOC_RESET_COUNTERS, 0, nargs, e)) 11 | return e->nr; 12 | 13 | ti_counters_reset(); 14 | 15 | query->rval = (ti_val_t *) ti_nil_get(); 16 | 17 | return e->nr; 18 | } 19 | -------------------------------------------------------------------------------- /inc/ti/fn/fnreverse.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_reverse(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_varr_t * src, * dst; 7 | 8 | if (!ti_val_is_array(query->rval)) 9 | return fn_call_try("reverse", query, nd, e); 10 | 11 | if (fn_nargs("reverse", DOC_LIST_REVERSE, 0, nargs, e)) 12 | return e->nr; 13 | 14 | src = (ti_varr_t *) query->rval; 15 | dst = ti_varr_create(src->vec->n); 16 | if (!dst) 17 | { 18 | ex_set_mem(e); 19 | return e->nr; 20 | } 21 | 22 | for (vec_each_rev(src->vec, ti_val_t, val)) 23 | { 24 | VEC_push(dst->vec, val); 25 | ti_incref(val); 26 | } 27 | 28 | ti_varr_set_may_flags(dst, src); 29 | 30 | ti_val_unsafe_drop(query->rval); 31 | query->rval = (ti_val_t *) dst; 32 | 33 | return e->nr; 34 | } 35 | -------------------------------------------------------------------------------- /inc/ti/fn/fnroot.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_root(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs("root", DOC_ROOT, 0, nargs, e)) 8 | return e->nr; 9 | 10 | if (query->collection) 11 | { 12 | query->rval = (ti_val_t *) query->collection->root; 13 | ti_incref(query->rval); 14 | } 15 | else 16 | query->rval = (ti_val_t *) ti_nil_get(); 17 | 18 | return e->nr; 19 | } 20 | -------------------------------------------------------------------------------- /inc/ti/fn/fnshutdown.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_shutdown(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_node_scope("shutdown", query, e) || 8 | ti_access_check_err(ti.access_node, query->user, TI_AUTH_CHANGE, e) || 9 | fn_nargs("shutdown", DOC_SHUTDOWN, 0, nargs, e)) 10 | return e->nr; 11 | 12 | log_warning( 13 | "user `%.*s` triggered a shutdown();", 14 | query->user->name->n, 15 | (const char *) query->user->name->data); 16 | 17 | ti_term(SIGINT); 18 | 19 | query->rval = (ti_val_t *) ti_nil_get(); 20 | 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fnstartswith.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_starts_with(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | _Bool starts_with; 8 | 9 | if (!ti_val_is_str(query->rval)) 10 | return fn_call_try("starts_with", query, nd, e); 11 | 12 | if (fn_nargs("starts_with", DOC_STR_STARTS_WITH, 1, nargs, e)) 13 | return e->nr; 14 | 15 | raw = (ti_raw_t *) query->rval; 16 | query->rval = NULL; 17 | 18 | if (ti_do_statement(query, nd->children, e) || 19 | fn_arg_str("starts_with", DOC_STR_STARTS_WITH, 1, query->rval, e)) 20 | goto failed; 21 | 22 | starts_with = ti_raw_startswith(raw, (ti_raw_t *) query->rval); 23 | ti_val_unsafe_drop(query->rval); 24 | query->rval = (ti_val_t *) ti_vbool_get(starts_with); 25 | 26 | failed: 27 | ti_val_unsafe_drop((ti_val_t *) raw); 28 | return e->nr; 29 | } 30 | -------------------------------------------------------------------------------- /inc/ti/fn/fnstr.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_str(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("str", DOC_STR, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (nargs == 0) 11 | { 12 | assert(query->rval == NULL); 13 | query->rval = ti_val_empty_str(); 14 | return e->nr; 15 | } 16 | 17 | if (ti_do_statement(query, nd->children, e)) 18 | return e->nr; 19 | 20 | return ti_val(query->rval)->to_str(&query->rval, e); 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fntasks.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_tasks(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | vec_t ** tasks = ti_query_tasks(query); 7 | 8 | if (fn_not_thingsdb_or_collection_scope("tasks", query, e) || 9 | fn_nargs("tasks", DOC_TASKS, 0, nargs, e)) 10 | return e->nr; 11 | 12 | query->rval = (ti_val_t *) ti_tasks_list(*tasks); 13 | if (!query->rval) 14 | ex_set_mem(e); 15 | return e->nr; 16 | } 17 | -------------------------------------------------------------------------------- /inc/ti/fn/fntimezonesinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_time_zones_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs("time_zones_info", DOC_TIME_ZONES_INFO, 0, nargs, e)) 8 | return e->nr; 9 | 10 | query->rval = ti_tz_as_mpval(); 11 | if (!query->rval) 12 | ex_set_mem(e); 13 | 14 | return e->nr; 15 | } 16 | -------------------------------------------------------------------------------- /inc/ti/fn/fntrim.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_trim(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | 8 | if (!ti_val_is_str(query->rval)) 9 | return fn_call_try("trim", query, nd, e); 10 | 11 | if (fn_nargs("trim", DOC_STR_TRIM, 0, nargs, e)) 12 | return e->nr; 13 | 14 | raw = (ti_raw_t *) query->rval; 15 | query->rval = (ti_val_t *) ti_str_trim(raw); 16 | if (!query->rval) 17 | ex_set_mem(e); 18 | 19 | ti_val_unsafe_drop((ti_val_t *) raw); 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fntrimleft.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_trim_left(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | 8 | if (!ti_val_is_str(query->rval)) 9 | return fn_call_try("trim_left", query, nd, e); 10 | 11 | if (fn_nargs("trim_left", DOC_STR_TRIM_LEFT, 0, nargs, e)) 12 | return e->nr; 13 | 14 | raw = (ti_raw_t *) query->rval; 15 | query->rval = (ti_val_t *) ti_str_trim_left(raw); 16 | if (!query->rval) 17 | ex_set_mem(e); 18 | 19 | ti_val_unsafe_drop((ti_val_t *) raw); 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fntrimright.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_trim_right(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | 8 | if (!ti_val_is_str(query->rval)) 9 | return fn_call_try("trim_right", query, nd, e); 10 | 11 | if (fn_nargs("trim_right", DOC_STR_TRIM_RIGHT, 0, nargs, e)) 12 | return e->nr; 13 | 14 | raw = (ti_raw_t *) query->rval; 15 | query->rval = (ti_val_t *) ti_str_trim_right(raw); 16 | if (!query->rval) 17 | ex_set_mem(e); 18 | 19 | ti_val_unsafe_drop((ti_val_t *) raw); 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fntype.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_type(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_val_t * type_str; 7 | 8 | if (fn_nargs("type", DOC_TYPE, 1, nargs, e)) 9 | return e->nr; 10 | 11 | if (ti_do_statement(query, nd->children, e)) 12 | return e->nr; 13 | 14 | type_str = ti_val_strv(query->rval); 15 | ti_val_unsafe_drop(query->rval); 16 | query->rval = type_str; 17 | 18 | return e->nr; 19 | } 20 | -------------------------------------------------------------------------------- /inc/ti/fn/fntypecount.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_type_count(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_type_t * type; 7 | size_t n; 8 | 9 | if (fn_not_collection_scope("type_count", query, e) || 10 | fn_nargs("type_count", DOC_TYPE_COUNT, 1, nargs, e) || 11 | ti_do_statement(query, nd->children, e) || 12 | fn_arg_str("type_count", DOC_TYPE_COUNT, 1, query->rval, e)) 13 | return e->nr; 14 | 15 | type = ti_types_by_raw(query->collection->types, (ti_raw_t *) query->rval); 16 | if (!type) 17 | return ti_raw_err_not_found((ti_raw_t *) query->rval, "type", e); 18 | 19 | n = ti_query_count_type(query, type); 20 | 21 | ti_val_unsafe_drop(query->rval); 22 | query->rval = (ti_val_t *) ti_vint_create((int64_t) n); 23 | 24 | if (!query->rval) 25 | ex_set_mem(e); 26 | 27 | return e->nr; 28 | } 29 | -------------------------------------------------------------------------------- /inc/ti/fn/fntypesinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_types_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_collection_scope("types_info", query, e) || 8 | fn_nargs("types_info", DOC_TYPES_INFO, 0, nargs, e)) 9 | return e->nr; 10 | 11 | query->rval = (ti_val_t *) ti_types_info( 12 | query->collection->types, 13 | ti_access_check( 14 | query->collection->access, 15 | query->user, 16 | TI_AUTH_CHANGE)); 17 | 18 | if (!query->rval) 19 | ex_set_mem(e); 20 | 21 | return e->nr; 22 | } 23 | -------------------------------------------------------------------------------- /inc/ti/fn/fnunwrap.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_unwrap(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_thing_t * thing; 7 | 8 | if (!ti_val_is_wrap(query->rval)) 9 | return fn_call_try("unwrap", query, nd, e); 10 | 11 | if (fn_nargs("unwrap", DOC_WTYPE_UNWRAP, 0, nargs, e)) 12 | return e->nr; 13 | 14 | thing = ((ti_wrap_t *) query->rval)->thing; 15 | ti_incref(thing); 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = (ti_val_t *) thing; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnupper.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_upper(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_raw_t * raw; 7 | 8 | if (!ti_val_is_str(query->rval)) 9 | return fn_call_try("upper", query, nd, e); 10 | 11 | if (fn_nargs("upper", DOC_STR_UPPER, 0, nargs, e)) 12 | return e->nr; 13 | 14 | raw = (ti_raw_t *) query->rval; 15 | query->rval = (ti_val_t *) ti_str_upper(raw); 16 | if (!query->rval) 17 | ex_set_mem(e); 18 | 19 | ti_val_unsafe_drop((ti_val_t *) raw); 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnusersinfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_users_info(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_not_thingsdb_scope("users_info", query, e) || 8 | /* check access */ 9 | ti_access_check_err( 10 | ti.access_thingsdb, 11 | query->user, TI_AUTH_GRANT, e 12 | ) || 13 | fn_nargs("users_info", DOC_USERS_INFO, 0, nargs, e)) 14 | return e->nr; 15 | 16 | query->rval = (ti_val_t *) ti_users_info(); 17 | if (!query->rval) 18 | ex_set_mem(e); 19 | 20 | return e->nr; 21 | } 22 | -------------------------------------------------------------------------------- /inc/ti/fn/fnvalue.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_value(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_val_t * val; 7 | 8 | if (!ti_val_is_member(query->rval)) 9 | return fn_call_try("value", query, nd, e); 10 | 11 | if (fn_nargs("value", DOC_ENUM_VALUE, 0, nargs, e)) 12 | return e->nr; 13 | 14 | val = VMEMBER(query->rval); 15 | ti_incref(val); 16 | ti_val_unsafe_drop(query->rval); 17 | query->rval = val; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /inc/ti/fn/fnweek.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_week(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | int week; 7 | 8 | if (!ti_val_is_datetime(query->rval)) 9 | return fn_call_try("week", query, nd, e); 10 | 11 | if (fn_nargs("week", DOC_DATETIME_WEEK, 0, nargs, e)) 12 | return e->nr; 13 | 14 | week = ti_datetime_week((ti_datetime_t *) query->rval); 15 | if (week < 0) 16 | { 17 | ex_set(e, EX_OVERFLOW, "date/time overflow"); 18 | return e->nr; 19 | } 20 | 21 | ti_val_unsafe_drop(query->rval); /* this destroys `raw_unit` */ 22 | query->rval = (ti_val_t *) ti_vint_create(week); 23 | /* no need to check for errors since a week number can't fail */ 24 | return e->nr; 25 | } 26 | -------------------------------------------------------------------------------- /inc/ti/fn/fnweekday.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_weekday(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | int weekday; 7 | 8 | if (!ti_val_is_datetime(query->rval)) 9 | return fn_call_try("weekday", query, nd, e); 10 | 11 | if (fn_nargs("weekday", DOC_DATETIME_WEEKDAY, 0, nargs, e)) 12 | return e->nr; 13 | 14 | weekday = ti_datetime_weekday((ti_datetime_t *) query->rval); 15 | if (weekday < 0) 16 | { 17 | ex_set(e, EX_OVERFLOW, "date/time overflow"); 18 | return e->nr; 19 | } 20 | 21 | ti_val_unsafe_drop(query->rval); /* this destroys `raw_unit` */ 22 | query->rval = (ti_val_t *) ti_vint_create(weekday); 23 | /* no need to check for errors since a weekday number can't fail */ 24 | return e->nr; 25 | } 26 | -------------------------------------------------------------------------------- /inc/ti/fn/fnwse.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_wse(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | 7 | if (fn_nargs_max("wse", DOC_WSE, 1, nargs, e)) 8 | return e->nr; 9 | 10 | if (!nargs) 11 | { 12 | query->rval = (ti_val_t *) ti_nil_get(); 13 | return e->nr; 14 | } 15 | 16 | return ti_do_statement(query, nd->children, e); 17 | } 18 | -------------------------------------------------------------------------------- /inc/ti/fn/fnyday.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_yday(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | int yday; 7 | 8 | if (!ti_val_is_datetime(query->rval)) 9 | return fn_call_try("yday", query, nd, e); 10 | 11 | if (fn_nargs("yday", DOC_DATETIME_YDAY, 0, nargs, e)) 12 | return e->nr; 13 | 14 | yday = ti_datetime_yday((ti_datetime_t *) query->rval); 15 | if (yday < 0) 16 | { 17 | ex_set(e, EX_OVERFLOW, "date/time overflow"); 18 | return e->nr; 19 | } 20 | 21 | ti_val_unsafe_drop(query->rval); /* this destroys `raw_unit` */ 22 | query->rval = (ti_val_t *) ti_vint_create(yday); 23 | if (!query->rval) 24 | ex_set_mem(e); 25 | 26 | return e->nr; 27 | } 28 | -------------------------------------------------------------------------------- /inc/ti/fn/fnzone.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int do__f_zone(ti_query_t * query, cleri_node_t * nd, ex_t * e) 4 | { 5 | const int nargs = fn_get_nargs(nd); 6 | ti_tz_t * tz; 7 | 8 | if (!ti_val_is_datetime(query->rval)) 9 | return fn_call_try("zone", query, nd, e); 10 | 11 | if (fn_nargs("zone", DOC_DATETIME_ZONE, 0, nargs, e)) 12 | return e->nr; 13 | 14 | tz = ((ti_datetime_t *) query->rval)->tz; 15 | ti_val_unsafe_drop(query->rval); 16 | 17 | query->rval = tz 18 | ? (ti_val_t *) ti_str_create(tz->name, tz->n) 19 | : (ti_val_t *) ti_nil_get(); 20 | 21 | if (!query->rval) 22 | ex_set_mem(e); 23 | 24 | return e->nr; 25 | } 26 | -------------------------------------------------------------------------------- /inc/ti/future.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/future.h 3 | */ 4 | #ifndef TI_FUTURE_H_ 5 | #define TI_FUTURE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_future_t * ti_future_create( 12 | ti_query_t * query, 13 | ti_module_t * module, 14 | size_t nargs, 15 | uint8_t deep, 16 | _Bool load); 17 | int ti_future_register(ti_future_t * future); 18 | void ti_future_destroy(ti_future_t * future); 19 | void ti_future_cancel(ti_future_t * future); 20 | void ti_future_stop(ti_future_t * future); 21 | 22 | #endif /* TI_FUTURE_H_ */ 23 | -------------------------------------------------------------------------------- /inc/ti/future.inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/future.inline.h 3 | */ 4 | #ifndef TI_FUTURE_INLINE_H_ 5 | #define TI_FUTURE_INLINE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define TI_FUTURE_DEEP_MASK 0x7f 15 | #define TI_FUTURE_LOAD_FLAG 0x80 16 | 17 | static inline void ti_future_forget_cb(ti_closure_t * cb) 18 | { 19 | if (!cb) 20 | return; 21 | ti_closure_dec_future(cb); 22 | ti_val_unsafe_drop((ti_val_t *) cb); 23 | } 24 | 25 | static inline uint8_t ti_future_deep(ti_future_t * future) 26 | { 27 | return future->options & TI_FUTURE_DEEP_MASK; 28 | } 29 | 30 | static inline uint8_t ti_future_should_load(ti_future_t * future) 31 | { 32 | return future->options & TI_FUTURE_LOAD_FLAG; 33 | } 34 | 35 | 36 | #endif /* TI_FUTURE_INLINE_H_ */ 37 | -------------------------------------------------------------------------------- /inc/ti/fwd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/fwd.h 3 | */ 4 | #ifndef TI_FWD_H_ 5 | #define TI_FWD_H_ 6 | 7 | 8 | typedef struct ti_fwd_s ti_fwd_t; 9 | 10 | #include 11 | #include 12 | 13 | 14 | ti_fwd_t * ti_fwd_create(uint16_t orig_pkg_id, ti_stream_t * src_stream); 15 | void ti_fwd_destroy(ti_fwd_t * fwd); 16 | 17 | struct ti_fwd_s 18 | { 19 | uint16_t orig_pkg_id; 20 | uint16_t dummy; /* must exist for casting */ 21 | ti_stream_t * stream; 22 | }; 23 | 24 | #endif /* TI_FWD_H_ */ 25 | -------------------------------------------------------------------------------- /inc/ti/gc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/gc.h 3 | */ 4 | #ifndef TI_GC_H_ 5 | #define TI_GC_H_ 6 | 7 | 8 | typedef struct ti_gc_s ti_gc_t; 9 | 10 | #include 11 | #include 12 | 13 | ti_gc_t * ti_gc_create(uint64_t change_id, ti_thing_t * thing); 14 | void ti_gc_destroy(ti_gc_t * gc); 15 | 16 | struct ti_gc_s 17 | { 18 | uint64_t change_id; /* committed change id during time of creation */ 19 | ti_thing_t * thing; /* with reference, thing marked for garbage collection */ 20 | }; 21 | 22 | static inline int ti_gc_walk(queue_t * queue, queue_cb cb, void * arg) 23 | { 24 | int rc; 25 | for (queue_each(queue, ti_gc_t, gc)) 26 | if ((rc = cb(gc->thing, arg))) 27 | return rc; 28 | return 0; 29 | } 30 | 31 | #endif /* TI_GC_H_ */ 32 | -------------------------------------------------------------------------------- /inc/ti/index.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/index.h 3 | */ 4 | #ifndef TI_INDEX_H_ 5 | #define TI_INDEX_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_index(ti_query_t * query, cleri_node_t * nd, ex_t * e); 12 | 13 | #endif /* TI_INDEX_H_ */ 14 | -------------------------------------------------------------------------------- /inc/ti/item.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/item.h 3 | */ 4 | #ifndef TI_ITEM_H_ 5 | #define TI_ITEM_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_item_t * ti_item_create(ti_raw_t * raw, ti_val_t * val); 12 | ti_item_t * ti_item_dup(ti_item_t * item); 13 | void ti_item_unassign_destroy(ti_item_t * item); 14 | void ti_item_unsafe_vdestroy(ti_item_t * item); 15 | 16 | #endif /* TI_ITEM_H_ */ 17 | -------------------------------------------------------------------------------- /inc/ti/item.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/item.t.h 3 | */ 4 | #ifndef TI_ITEM_T_H_ 5 | #define TI_ITEM_T_H_ 6 | 7 | typedef struct ti_item_s ti_item_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_item_s 13 | { 14 | ti_raw_t * key; /* with reference, valid names must always be of type 15 | ti_name_t, but casted to ti_raw_t */ 16 | ti_val_t * val; /* with reference */ 17 | }; 18 | 19 | #endif /* TI_ITEM_T_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/mapping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mapping.h 3 | */ 4 | #ifndef TI_MAPPING_H_ 5 | #define TI_MAPPING_H_ 6 | 7 | typedef struct ti_mapping_s ti_mapping_t; 8 | 9 | #include 10 | 11 | ti_mapping_t * ti_mapping_new(ti_field_t * t_field, ti_field_t * f_field); 12 | 13 | struct ti_mapping_s 14 | { 15 | ti_field_t * t_field; /* weak reference */ 16 | ti_field_t * f_field; /* weak reference */ 17 | }; 18 | 19 | #endif /* TI_MAPPING_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/member.inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/member.inline.h 3 | */ 4 | #ifndef TI_MEMBER_INLINE_H_ 5 | #define TI_MEMBER_INLINE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | static inline const char * ti_member_enum_name(ti_member_t * member) 15 | { 16 | return member->enum_->name; 17 | } 18 | 19 | static inline uint16_t ti_member_enum_id(ti_member_t * member) 20 | { 21 | return member->enum_->enum_id; 22 | } 23 | 24 | static inline ti_raw_t * ti_member_enum_get_rname(ti_member_t * member) 25 | { 26 | ti_raw_t * rname = member->enum_->rname; 27 | ti_incref(rname); 28 | return rname; 29 | } 30 | 31 | #endif /* TI_MEMBER_INLINE_H_ */ 32 | -------------------------------------------------------------------------------- /inc/ti/member.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/member.t.h 3 | */ 4 | #ifndef TI_MEMBER_T_H_ 5 | #define TI_MEMBER_T_H_ 6 | 7 | #define VMEMBER(__x) ((ti_member_t *) (__x))->val 8 | 9 | typedef struct ti_member_s ti_member_t; 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | struct ti_member_s 17 | { 18 | uint32_t ref; 19 | uint8_t tp; 20 | uint8_t unused_flags; 21 | uint16_t idx; /* index in enum_->vec */ 22 | ti_enum_t * enum_; /* parent enum */ 23 | ti_name_t * name; /* with reference */ 24 | ti_val_t * val; /* with reference */ 25 | }; 26 | 27 | #endif /* TI_MEMBER_T_H_ */ 28 | -------------------------------------------------------------------------------- /inc/ti/method.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/method.h 3 | */ 4 | #ifndef TI_METHOD_T_H_ 5 | #define TI_METHOD_T_H_ 6 | 7 | typedef struct ti_method_s ti_method_t; 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | struct ti_method_s 14 | { 15 | ti_name_t * name; /* name of the method */ 16 | ti_raw_t * doc; /* documentation, may be NULL */ 17 | ti_raw_t * def; /* formatted definition, may be NULL */ 18 | ti_closure_t * closure; /* closure */ 19 | }; 20 | 21 | #endif /* TI_METHOD_T_H_ */ 22 | -------------------------------------------------------------------------------- /inc/ti/mod/expose.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/expose.t.h 3 | */ 4 | #ifndef TI_MOD_EXPOSE_T_H_ 5 | #define TI_MOD_EXPOSE_T_H_ 6 | 7 | #define TI_EXPOSE "module.json" 8 | 9 | typedef struct ti_mod_expose_s ti_mod_expose_t; 10 | 11 | #include 12 | #include 13 | 14 | struct ti_mod_expose_s 15 | { 16 | uint8_t * deep; /* NULL or 0..127 */ 17 | _Bool * load; /* NULL or true/false */ 18 | char * doc; /* NULL or string */ 19 | vec_t * argmap; /* ti_item_t */ 20 | vec_t * defaults; /* ti_item_t */ 21 | ti_closure_t * closure; /* closure */ 22 | ti_raw_t * def; /* closure definition */ 23 | }; 24 | 25 | #endif /* TI_MOD_EXPOSE_T_H_ */ 26 | -------------------------------------------------------------------------------- /inc/ti/mod/github.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/github.h 3 | */ 4 | #ifndef TI_MOD_GITHUB_H_ 5 | #define TI_MOD_GITHUB_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | _Bool ti_mod_github_test(const char * s, size_t n); 14 | int ti_mod_github_init( 15 | ti_mod_github_t * gh, 16 | const char * s, 17 | size_t n, 18 | ex_t * e); 19 | ti_mod_github_t * ti_mod_github_create(const char * s, size_t n, ex_t * e); 20 | void ti_mod_github_download(uv_work_t * work); 21 | void ti_mod_github_manifest(uv_work_t * work); 22 | void ti_mod_github_destroy(ti_mod_github_t * gh); 23 | const char * ti_mod_github_code_str(ti_mod_github_t * gh); 24 | 25 | 26 | #endif /* TI_MOD_GITHUB_H_ */ 27 | -------------------------------------------------------------------------------- /inc/ti/mod/github.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/github.t.h 3 | */ 4 | #ifndef TI_MOD_GITHUB_T_H_ 5 | #define TI_MOD_GITHUB_T_H_ 6 | 7 | typedef struct ti_mod_github_s ti_mod_github_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | struct ti_mod_github_s 16 | { 17 | char * owner; 18 | char * repo; 19 | char * ref; /* NULL or tag, branch etc. */ 20 | char * token_header; /* NULL when public, not visible */ 21 | char * manifest_url; 22 | }; 23 | 24 | #endif /* TI_MOD_GITHUB_T_H_ */ 25 | -------------------------------------------------------------------------------- /inc/ti/mod/manifest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/manifest.h 3 | */ 4 | #ifndef TI_MOD_MANIFEST_H_ 5 | #define TI_MOD_MANIFEST_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_mod_manifest_read( 12 | ti_mod_manifest_t * manifest, 13 | char * source_err, 14 | const void * data, 15 | size_t n); 16 | int ti_mod_manifest_local(ti_mod_manifest_t * manifest, ti_module_t * module); 17 | _Bool ti_mod_manifest_skip_install( 18 | ti_mod_manifest_t * manifest, 19 | ti_module_t * module); 20 | int ti_mod_manifest_store(const char * module_path, void * data, size_t n); 21 | void ti_mod_manifest_clear(ti_mod_manifest_t * manifest); 22 | 23 | static inline void ti_mod_manifest_init(ti_mod_manifest_t * manifest) 24 | { 25 | memset(manifest, 0, sizeof(ti_mod_manifest_t)); 26 | } 27 | 28 | #endif /* TI_MOD_MANIFEST_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/mod/work.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/work.h 3 | */ 4 | #ifndef TI_MOD_WORK_H_ 5 | #define TI_MOD_WORK_H_ 6 | 7 | #include 8 | 9 | void ti_mod_work_destroy(ti_mod_work_t * data); 10 | 11 | #endif /* TI_MOD_WORK_H_ */ 12 | -------------------------------------------------------------------------------- /inc/ti/mod/work.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/work.t.h 3 | */ 4 | #ifndef TI_MOD_WORK_T_H_ 5 | #define TI_MOD_WORK_T_H_ 6 | 7 | typedef struct ti_mod_work_s ti_mod_work_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | struct ti_mod_work_s 16 | { 17 | ti_module_t * module; 18 | buf_t buf; 19 | ti_mod_manifest_t manifest; 20 | void (*download_cb) (uv_work_t *); 21 | _Bool rtxt; /* Python, requirements.txt */ 22 | }; 23 | 24 | #endif /* TI_MOD_WORK_T_H_ */ 25 | -------------------------------------------------------------------------------- /inc/ti/modules.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/moduless.h 3 | */ 4 | #ifndef TI_MODULES_H_ 5 | #define TI_MODULES_H_ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | ti_varr_t * ti_modules_info(_Bool with_conf); 17 | void ti_modules_init(void); 18 | void ti_modules_load(void); 19 | void ti_modules_cancel_futures(void); 20 | _Bool ti_modules_ready(void); 21 | void ti_modules_stop_and_destroy(void); 22 | int ti_modules_rename(ti_module_t * module, const char * s, size_t n); 23 | 24 | static inline ti_module_t * ti_modules_by_raw(ti_raw_t * raw) 25 | { 26 | return smap_getn(ti.modules, (const char *) raw->data, raw->n); 27 | } 28 | 29 | static inline ti_module_t * ti_modules_by_strn(const char * s, size_t n) 30 | { 31 | return smap_getn(ti.modules, s, n); 32 | } 33 | 34 | #endif /* TI_MODULES_H_ */ 35 | -------------------------------------------------------------------------------- /inc/ti/name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/name.h 3 | */ 4 | #ifndef TI_NAME_H_ 5 | #define TI_NAME_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_name_t * ti_name_create(const char * str, size_t n); 12 | void ti_name_destroy(ti_name_t * name); 13 | _Bool ti_name_is_valid_strn(const char * str, size_t n); 14 | 15 | static inline void ti_name_drop(ti_name_t * name) 16 | { 17 | if (name && !--name->ref) 18 | ti_name_destroy(name); 19 | } 20 | 21 | static inline void ti_name_unsafe_drop(ti_name_t * name) 22 | { 23 | if (!--name->ref) 24 | ti_name_destroy(name); 25 | } 26 | 27 | /* added for issue #394 */ 28 | static inline int ti_name_to_pk(ti_name_t * name, msgpack_packer * pk) 29 | { 30 | return mp_pack_ext(pk, MPACK_EXT_NAME, name->str, name->n); 31 | } 32 | 33 | #endif /* TI_NAME_H_ */ 34 | -------------------------------------------------------------------------------- /inc/ti/name.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/name.t.h 3 | */ 4 | #ifndef TI_NAME_T_H_ 5 | #define TI_NAME_T_H_ 6 | 7 | /* it is possible to extend the name limit without consequences */ 8 | #define TI_NAME_MAX 255 9 | 10 | typedef struct ti_name_s ti_name_t; 11 | 12 | #include 13 | 14 | /* 15 | * name can be cast to raw. the difference is in `char str[]`, but the other 16 | * fields map to `raw`. therefore the `tp` of name should be equal to `raw` 17 | */ 18 | struct ti_name_s 19 | { 20 | uint32_t ref; 21 | uint8_t tp; 22 | uint8_t unused_flags; 23 | int:16; 24 | uint32_t n; 25 | char str[]; /* null terminated string */ 26 | }; 27 | 28 | #endif /* TI_NAME_T_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/ncache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/ncache.h 3 | */ 4 | #ifndef TI_NCACHE_H_ 5 | #define TI_NCACHE_H_ 6 | 7 | typedef struct ti_ncache_s ti_ncache_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | ti_ncache_t * ti_ncache_create(char * query, size_t n); 15 | void ti_ncache_destroy(ti_ncache_t * ncache); 16 | int ti_ncache_gen_node_data( 17 | ti_qbind_t * syntax, 18 | vec_t * vcache, 19 | cleri_node_t * nd, 20 | ex_t * e); 21 | 22 | struct ti_ncache_s 23 | { 24 | char * query; 25 | vec_t * immutable_cache; 26 | }; 27 | 28 | #endif /* TI_NCACHE_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/nil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/nil.h 3 | */ 4 | #ifndef TI_NIL_H_ 5 | #define TI_NIL_H_ 6 | 7 | typedef struct ti_nil_s ti_nil_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_nil_s 13 | { 14 | uint32_t ref; 15 | uint8_t tp; 16 | long:24; 17 | void * nil; 18 | }; 19 | 20 | extern ti_nil_t nil__val; 21 | 22 | static inline ti_nil_t * ti_nil_get(void) 23 | { 24 | ti_incref(&nil__val); 25 | return &nil__val; 26 | } 27 | 28 | static inline _Bool ti_nil_no_ref(void) 29 | { 30 | return nil__val.ref == 1; 31 | } 32 | 33 | #endif /* TI_NIL_H_ */ 34 | -------------------------------------------------------------------------------- /inc/ti/opr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/opr.h 3 | */ 4 | #ifndef TI_OPR_H_ 5 | #define TI_OPR_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_opr_a_to_b(ti_val_t * a, cleri_node_t * nd, ti_val_t ** b, ex_t * e); 12 | _Bool ti__opr_eq_(ti_val_t * a, ti_val_t * b); 13 | int ti_opr_compare(ti_val_t * a, ti_val_t * b, ex_t * e); 14 | 15 | static inline int ti_opr_compare_desc(ti_val_t * a, ti_val_t * b, ex_t * e) 16 | { 17 | return ti_opr_compare(b, a, e); 18 | } 19 | 20 | static inline _Bool ti_opr_eq(ti_val_t * a, ti_val_t * b) 21 | { 22 | return a == b || ti__opr_eq_(a, b); 23 | } 24 | 25 | #endif /* TI_OPR_H_ */ 26 | -------------------------------------------------------------------------------- /inc/ti/opr/eq.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static inline int opr__eq(ti_val_t * a, ti_val_t ** b, ex_t * e) 4 | { 5 | _Bool bool_ = ti_opr_eq(a, *b); 6 | 7 | ti_val_unsafe_drop(*b); 8 | *b = (ti_val_t *) ti_vbool_get(bool_); 9 | 10 | return e->nr; 11 | } 12 | -------------------------------------------------------------------------------- /inc/ti/opr/ne.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static inline int opr__ne(ti_val_t * a, ti_val_t ** b, ex_t * e) 4 | { 5 | _Bool bool_ = !ti_opr_eq(a, *b); 6 | 7 | ti_val_unsafe_drop(*b); 8 | *b = (ti_val_t *) ti_vbool_get(bool_); 9 | 10 | return e->nr; 11 | } 12 | -------------------------------------------------------------------------------- /inc/ti/opr/sl.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int opr__sl(ti_val_t * a, ti_val_t ** b, ex_t * e) 4 | { 5 | int64_t int_ = 0; /* set to 0 only to prevent warning */ 6 | ti_opr_perm_t perm = TI_OPR_PERM(a, *b); 7 | switch(perm) 8 | { 9 | default: 10 | ex_set(e, EX_TYPE_ERROR, 11 | "bitwise `<<` not supported between `%s` and `%s`", 12 | ti_val_str(a), ti_val_str(*b)); 13 | return e->nr; 14 | 15 | case OPR_INT_INT: 16 | int_ = VINT(a) << VINT(*b); 17 | break; 18 | 19 | case OPR_INT_BOOL: 20 | int_ = VINT(a) << VBOOL(*b); 21 | break; 22 | 23 | case OPR_BOOL_INT: 24 | int_ = VBOOL(a) << VINT(*b); 25 | break; 26 | 27 | case OPR_BOOL_BOOL: 28 | int_ = VBOOL(a) << VBOOL(*b); 29 | break; 30 | 31 | } 32 | if (ti_val_make_int(b, int_)) 33 | ex_set_mem(e); 34 | return e->nr; 35 | } 36 | -------------------------------------------------------------------------------- /inc/ti/opr/sr.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int opr__sr(ti_val_t * a, ti_val_t ** b, ex_t * e) 4 | { 5 | int64_t int_ = 0; /* set to 0 only to prevent warning */ 6 | ti_opr_perm_t perm = TI_OPR_PERM(a, *b); 7 | switch(perm) 8 | { 9 | default: 10 | ex_set(e, EX_TYPE_ERROR, 11 | "bitwise `>>` not supported between `%s` and `%s`", 12 | ti_val_str(a), ti_val_str(*b)); 13 | return e->nr; 14 | 15 | case OPR_INT_INT: 16 | int_ = VINT(a) >> VINT(*b); 17 | break; 18 | 19 | case OPR_INT_BOOL: 20 | int_ = VINT(a) >> VBOOL(*b); 21 | break; 22 | 23 | case OPR_BOOL_INT: 24 | int_ = VBOOL(a) >> VINT(*b); 25 | break; 26 | 27 | case OPR_BOOL_BOOL: 28 | int_ = VBOOL(a) >> VBOOL(*b); 29 | break; 30 | 31 | } 32 | if (ti_val_make_int(b, int_)) 33 | ex_set_mem(e); 34 | return e->nr; 35 | } 36 | -------------------------------------------------------------------------------- /inc/ti/pipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pipe.h 3 | */ 4 | #ifndef TI_PIPE_H_ 5 | #define TI_PIPE_H_ 6 | 7 | #include 8 | 9 | char * ti_pipe_name(const char * prefix, uv_pipe_t * client); 10 | 11 | #endif /* TI_PIPE_H_ */ 12 | -------------------------------------------------------------------------------- /inc/ti/pkg.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/pkg.t.h 3 | */ 4 | #ifndef TI_PKG_T_H_ 5 | #define TI_PKG_T_H_ 6 | 7 | /* 1GB */ 8 | #define TI_PKG_MAX_SIZE 1073741824 9 | 10 | typedef struct ti_pkg_s ti_pkg_t; 11 | 12 | #include 13 | 14 | struct ti_pkg_s 15 | { 16 | uint32_t n; /* size of data */ 17 | uint16_t id; /* id 0 is used for fire-and-forget packages */ 18 | uint8_t tp; /* see proto.h for protocol types */ 19 | uint8_t ntp; /* used as check-bit */ 20 | unsigned char data[]; 21 | }; 22 | 23 | #endif /* TI_PKG_T_H_ */ 24 | -------------------------------------------------------------------------------- /inc/ti/preopr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/preopr.h 3 | */ 4 | #ifndef TI_PREOPR_H_ 5 | #define TI_PREOPR_H_ 6 | 7 | #include 8 | #include 9 | 10 | int ti_preopr_bind(const char * s, size_t n); 11 | int ti_preopr_calc(int preopr, ti_val_t ** val, ex_t * e); 12 | 13 | 14 | #endif /* TI_PREOPR_H_ */ 15 | -------------------------------------------------------------------------------- /inc/ti/proc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/proc.h 3 | */ 4 | #ifndef TI_PROC_H_ 5 | #define TI_PROC_H_ 6 | 7 | typedef struct ti_proc_s ti_proc_t; 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | void ti_proc_init(ti_proc_t * proc, ti_module_t * module); 14 | int ti_proc_load(ti_proc_t * proc); 15 | int ti_proc_write_request(ti_proc_t * proc, uv_write_t * req, uv_buf_t * wrbuf); 16 | 17 | #endif /* TI_PROC_H_ */ 18 | -------------------------------------------------------------------------------- /inc/ti/proc.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/proc.t.h 3 | */ 4 | #ifndef TI_PROC_T_H_ 5 | #define TI_PROC_T_H_ 6 | 7 | typedef struct ti_proc_s ti_proc_t; 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | struct ti_proc_s 14 | { 15 | uv_process_t process; 16 | uv_process_options_t options; 17 | uv_stdio_container_t child_stdio[3]; 18 | uv_pipe_t child_stdin; 19 | uv_pipe_t child_stdout; 20 | ti_module_t * module; 21 | buf_t buf; 22 | }; 23 | 24 | #endif /* TI_PROC_T_H_ */ 25 | -------------------------------------------------------------------------------- /inc/ti/prop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/prop.h 3 | */ 4 | #ifndef TI_PROP_H_ 5 | #define TI_PROP_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_prop_t * ti_prop_create(ti_name_t * name, ti_val_t * val); 12 | ti_prop_t * ti_prop_dup(ti_prop_t * prop); 13 | void ti_prop_destroy(ti_prop_t * prop); 14 | void ti_prop_unassign_destroy(ti_prop_t * prop); 15 | void ti_prop_unsafe_vdestroy(ti_prop_t * prop); 16 | 17 | #endif /* TI_PROP_H_ */ 18 | -------------------------------------------------------------------------------- /inc/ti/prop.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/prop.t.h 3 | */ 4 | #ifndef TI_PROP_T_H_ 5 | #define TI_PROP_T_H_ 6 | 7 | typedef struct ti_prop_s ti_prop_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_prop_s 13 | { 14 | ti_name_t * name; /* with reference */ 15 | ti_val_t * val; /* with reference */ 16 | }; 17 | 18 | #endif /* TI_PROP_T_H_ */ 19 | -------------------------------------------------------------------------------- /inc/ti/proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/proto.h 3 | */ 4 | #ifndef TI_PROTO_H_ 5 | #define TI_PROTO_H_ 6 | 7 | #include 8 | 9 | const char * ti_proto_str(ti_proto_enum_t tp); 10 | 11 | #endif /* TI_PROTO_H_ */ 12 | -------------------------------------------------------------------------------- /inc/ti/qbind.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/qbind.h 3 | */ 4 | #ifndef TI_QBIND_H_ 5 | #define TI_QBIND_H_ 6 | 7 | #include 8 | #include 9 | 10 | void ti_qbind_init(void); 11 | void ti_qbind_probe(ti_qbind_t * qbind, cleri_node_t * nd); 12 | 13 | #endif /* TI_QBIND_H_ */ 14 | -------------------------------------------------------------------------------- /inc/ti/qcache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/qcache.h 3 | */ 4 | #ifndef TI_QCACHE_H_ 5 | #define TI_QCACHE_H_ 6 | 7 | #include 8 | #include 9 | 10 | /* 11 | * Node info: 12 | * - `cached_queries` 13 | * 14 | * Counters: 15 | * - `queries_from_cache` 16 | * - `unused_cache` 17 | * 18 | */ 19 | 20 | 21 | int ti_qcache_create(void); 22 | void ti_qcache_destroy(void); 23 | ti_query_t * ti_qcache_get_query(const char * str, size_t n, uint8_t flags); 24 | void ti_qcache_return(ti_query_t * query); 25 | void ti_qcache_cleanup(void); 26 | _Bool ti_qcache_require_away(void); 27 | 28 | 29 | #endif /* TI_QCACHE_H_ */ 30 | -------------------------------------------------------------------------------- /inc/ti/raw.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/raw.t.h 3 | */ 4 | #ifndef TI_RAW_T_H_ 5 | #define TI_RAW_T_H_ 6 | 7 | typedef struct ti_raw_s ti_raw_t; 8 | 9 | #include 10 | 11 | struct ti_raw_s 12 | { 13 | uint32_t ref; 14 | uint8_t tp; 15 | uint8_t unused_flags; 16 | int:16; 17 | uint32_t n; 18 | unsigned char data[]; 19 | }; 20 | 21 | #endif /* TI_RAW_T_H_ */ 22 | -------------------------------------------------------------------------------- /inc/ti/regex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/regex.h 3 | */ 4 | #ifndef TI_REGEX_H_ 5 | #define TI_REGEX_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | ti_regex_t * ti_regex_from_strn(const char * str, size_t n, ex_t * e); 13 | ti_regex_t * ti_regex_from_str(const char * str); 14 | ti_regex_t * ti_regex_create(ti_raw_t * pattern, ti_raw_t * flags, ex_t * e); 15 | void ti_regex_destroy(ti_regex_t * regex); 16 | 17 | #endif /* TI_REGEX_H_ */ 18 | -------------------------------------------------------------------------------- /inc/ti/req.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/req.h 3 | */ 4 | #ifndef TI_REQ_H_ 5 | #define TI_REQ_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int ti_req_create( 13 | ti_stream_t * stream, 14 | ti_pkg_t * pkg_req, 15 | uint32_t timeout, 16 | ti_req_cb cb, 17 | void * data); 18 | void ti_req_destroy(ti_req_t * req); 19 | void ti_req_cancel(ti_req_t * req); 20 | void ti_req_result(ti_req_t * req); 21 | 22 | #endif /* TI_REQ_H_ */ 23 | -------------------------------------------------------------------------------- /inc/ti/req.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/req.t.h 3 | */ 4 | #ifndef TI_REQ_T_H_ 5 | #define TI_REQ_T_H_ 6 | 7 | typedef struct ti_req_s ti_req_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | typedef void (*ti_req_cb)(ti_req_t * req, ex_enum status); 15 | 16 | struct ti_req_s 17 | { 18 | ti_stream_t * stream; 19 | ti_pkg_t * pkg_req; 20 | ti_pkg_t * pkg_res; 21 | void * data; 22 | uv_timer_t * timer; 23 | ti_req_cb cb_; 24 | }; 25 | 26 | #endif /* TI_REQ_T_H_ */ 27 | -------------------------------------------------------------------------------- /inc/ti/restore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/restore.h 3 | */ 4 | #ifndef TI_RESTORE_H_ 5 | #define TI_RESTORE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | char * ti_restore_task(const char * fn, size_t n); 12 | int ti_restore_chk(const char * fn, size_t n, ex_t * e); 13 | int ti_restore_unp(const char * restore_task, ex_t * e); 14 | _Bool ti_restore_is_busy(void); 15 | void ti_restore_finished(void); 16 | int ti_restore_master(ti_user_t * user /* may be NULL */, _Bool restore_tasks); 17 | int ti_restore_slave(void); 18 | 19 | #endif /* TI_RESTORE_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/room.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/room.t.h 3 | */ 4 | #ifndef TI_ROOM_T_H_ 5 | #define TI_ROOM_T_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define TI_ROOM_ENAME_MIN 1 13 | #define TI_ROOM_ENAME_MAX 255 14 | 15 | typedef struct ti_room_s ti_room_t; 16 | 17 | struct ti_room_s 18 | { 19 | uint32_t ref; 20 | uint8_t tp; 21 | uint8_t unused_flags; 22 | int:16; 23 | uint64_t id; 24 | ti_name_t * name; /* Name is optional, might be NULL */ 25 | ti_collection_t * collection; /* NULL in non-collection scope */ 26 | vec_t * listeners; 27 | }; 28 | 29 | #endif /* TI_ROOM_T_H_ */ 30 | -------------------------------------------------------------------------------- /inc/ti/rooms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/rooms.h 3 | */ 4 | #ifndef TI_ROOMS_H_ 5 | #define TI_ROOMS_H_ 6 | 7 | #include 8 | #include 9 | 10 | 11 | #endif /* TI_ROOMS_H_ */ 12 | -------------------------------------------------------------------------------- /inc/ti/rpkg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/rpkg.h 3 | */ 4 | #ifndef TI_RPKG_H_ 5 | #define TI_RPKG_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_rpkg_t * ti_rpkg_create(ti_pkg_t * pkg); 12 | void ti_rpkg_drop(ti_rpkg_t * rpkg); 13 | 14 | #endif /* TI_RPKG_H_ */ 15 | -------------------------------------------------------------------------------- /inc/ti/rpkg.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/rpkg.t.h 3 | */ 4 | #ifndef TI_RPKG_T_H_ 5 | #define TI_RPKG_T_H_ 6 | 7 | typedef struct ti_rpkg_s ti_rpkg_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_rpkg_s 13 | { 14 | uint32_t ref; 15 | long:32; /* required for alignment with ti_cpkg_t */ 16 | ti_pkg_t * pkg; /* must align with ti_cpkg_t */ 17 | }; 18 | 19 | #endif /* TI_RPKG_T_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/scope.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/scope.t.h 3 | */ 4 | #ifndef TI_SCOPE_T_H_ 5 | #define TI_SCOPE_T_H_ 6 | 7 | typedef struct ti_scope_s ti_scope_t; 8 | typedef struct ti_scope_name_s ti_scope_name_t; 9 | 10 | typedef enum 11 | { 12 | TI_SCOPE_THINGSDB, 13 | TI_SCOPE_NODE, 14 | TI_SCOPE_COLLECTION, 15 | } ti_scope_enum_t; 16 | 17 | #include 18 | 19 | struct ti_scope_name_s 20 | { 21 | const char * name; 22 | size_t sz; 23 | }; 24 | 25 | typedef union 26 | { 27 | uint32_t node_id; 28 | ti_scope_name_t collection_name; 29 | } ti_scope_via_t; 30 | 31 | struct ti_scope_s 32 | { 33 | ti_scope_enum_t tp; 34 | ti_scope_via_t via; 35 | }; 36 | 37 | #endif /* TI_SCOPE_T_H_ */ 38 | -------------------------------------------------------------------------------- /inc/ti/signals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * signals.h 3 | */ 4 | #ifndef TI_SIGNALS_H_ 5 | #define TI_SIGNALS_H_ 6 | 7 | int ti_signals_init(void); 8 | 9 | #endif /* TI_SIGNALS_H_ */ 10 | -------------------------------------------------------------------------------- /inc/ti/store/storeaccess.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/access.h 3 | */ 4 | #ifndef TI_STORE_ACCESS_H_ 5 | #define TI_STORE_ACCESS_H_ 6 | 7 | #include 8 | 9 | int ti_store_access_store(const vec_t * access, const char * fn); 10 | int ti_store_access_restore(vec_t ** access, const char * fn); 11 | 12 | #endif /* TI_STORE_ACCESS_H_ */ 13 | -------------------------------------------------------------------------------- /inc/ti/store/storecollections.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/collections.h 3 | */ 4 | #ifndef TI_STORE_COLLECTIONS_H_ 5 | #define TI_STORE_COLLECTIONS_H_ 6 | 7 | int ti_store_collections_store(const char * fn); 8 | int ti_store_collections_restore(const char * fn); 9 | 10 | #endif /* TI_STORE_COLLECTIONS_H_ */ 11 | -------------------------------------------------------------------------------- /inc/ti/store/storeenums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storeenums.h 3 | */ 4 | #ifndef TI_STORE_ENUMS_H_ 5 | #define TI_STORE_ENUMS_H_ 6 | 7 | #include 8 | 9 | int ti_store_enums_store(ti_enums_t * enums, const char * fn); 10 | int ti_store_enums_restore(ti_enums_t * enums, imap_t * names, const char * fn); 11 | int ti_store_enums_restore_members( 12 | ti_enums_t * enums, 13 | imap_t * names, 14 | const char * fn); 15 | 16 | #endif /* TI_STORE_ENUMS_H_ */ 17 | -------------------------------------------------------------------------------- /inc/ti/store/storegcollect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storegcollect.h 3 | */ 4 | #ifndef TI_STORE_GCOLLECT_H_ 5 | #define TI_STORE_GCOLLECT_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_store_gcollect_store(queue_t * gc, const char * fn); 12 | int ti_store_gcollect_store_data(queue_t * gc, const char * fn); 13 | int ti_store_gcollect_restore(ti_collection_t * collection, const char * fn); 14 | int ti_store_gcollect_restore_data( 15 | ti_collection_t * collection, 16 | imap_t * names, 17 | const char * fn); 18 | 19 | #endif /* TI_STORE_GCOLLECT_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/store/storemodules.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storemodules.h 3 | */ 4 | #ifndef TI_STORE_MODULES_H_ 5 | #define TI_STORE_MODULES_H_ 6 | 7 | int ti_store_modules_store(const char * fn); 8 | int ti_store_modules_restore(const char * fn); 9 | 10 | #endif /* TI_STORE_MODULES_H_ */ 11 | -------------------------------------------------------------------------------- /inc/ti/store/storenamedrooms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storenamedrooms.h 3 | */ 4 | #ifndef TI_STORE_NAMED_ROOMS_H_ 5 | #define TI_STORE_NAMED_ROOMS_H_ 6 | 7 | #include 8 | #include 9 | 10 | int ti_store_named_rooms_store(smap_t * named_rooms, const char * fn); 11 | int ti_store_named_rooms_restore(const char * fn, ti_collection_t * collection); 12 | 13 | #endif /* TI_STORE_NAMED_ROOMS_H_ */ 14 | 15 | 16 | -------------------------------------------------------------------------------- /inc/ti/store/storenames.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storenames.h 3 | */ 4 | #ifndef TI_STORE_NAMES_H_ 5 | #define TI_STORE_NAMES_H_ 6 | 7 | int ti_store_names_store(const char * fn); 8 | imap_t * ti_store_names_restore(const char * fn); 9 | 10 | #endif /* TI_STORE_NAMES_H_ */ 11 | -------------------------------------------------------------------------------- /inc/ti/store/storeprocedures.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storeprocedures.h 3 | */ 4 | #ifndef TI_STORE_PROCEDURES_H_ 5 | #define TI_STORE_PROCEDURES_H_ 6 | 7 | #include 8 | #include 9 | 10 | int ti_store_procedures_store(smap_t * procedures, const char * fn); 11 | int ti_store_procedures_restore( 12 | smap_t * procedures, 13 | const char * fn, 14 | ti_collection_t * collection); 15 | 16 | #endif /* TI_STORE_PROCEDURES_H_ */ 17 | -------------------------------------------------------------------------------- /inc/ti/store/storestatus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storestatus.h 3 | */ 4 | #ifndef TI_STORE_STATUS_H_ 5 | #define TI_STORE_STATUS_H_ 6 | 7 | 8 | int ti_store_status_store(const char * fn); 9 | int ti_store_status_restore(const char * fn); 10 | 11 | 12 | #endif /* TI_STORE_STATUS_H_ */ 13 | -------------------------------------------------------------------------------- /inc/ti/store/storetasks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/tasks.h 3 | */ 4 | #ifndef TI_STORE_TASKS_H_ 5 | #define TI_STORE_TASKS_H_ 6 | 7 | #include 8 | #include 9 | 10 | int ti_store_tasks_store(vec_t * tasks, const char * fn); 11 | int ti_store_tasks_restore( 12 | vec_t ** tasks, 13 | const char * fn, 14 | ti_collection_t * collection); 15 | 16 | #endif /* TI_STORE_TASKS_H_ */ 17 | -------------------------------------------------------------------------------- /inc/ti/store/storethings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storethings.h 3 | */ 4 | #ifndef TI_STORE_THINGS_H_ 5 | #define TI_STORE_THINGS_H_ 6 | 7 | #include 8 | 9 | int ti_store_things_store(imap_t * things, const char * fn); 10 | int ti_store_things_store_data(imap_t * things, const char * fn); 11 | int ti_store_things_restore(ti_collection_t * collection, const char * fn); 12 | int ti_store_things_restore_data( 13 | ti_collection_t * collection, 14 | imap_t * names, 15 | const char * fn); 16 | 17 | #endif /* TI_STORE_COLLECTIONS_H_ */ 18 | -------------------------------------------------------------------------------- /inc/ti/store/storetypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storetypes.h 3 | */ 4 | #ifndef TI_STORE_TYPES_H_ 5 | #define TI_STORE_TYPES_H_ 6 | 7 | #include 8 | 9 | int ti_store_types_store(ti_types_t * types, const char * fn); 10 | int ti_store_types_restore(ti_types_t * types, imap_t * names, const char * fn); 11 | 12 | #endif /* TI_STORE_TYPES_H_ */ 13 | -------------------------------------------------------------------------------- /inc/ti/store/storeusers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/store/storeusers.h 3 | */ 4 | #ifndef TI_STORE_USERS_H_ 5 | #define TI_STORE_USERS_H_ 6 | 7 | int ti_store_users_store(const char * fn); 8 | int ti_store_users_restore(const char * fn); 9 | 10 | #endif /* TI_STORE_USERS_H_ */ 11 | -------------------------------------------------------------------------------- /inc/ti/str.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/str.h 3 | */ 4 | #ifndef TI_STR_H_ 5 | #define TI_STR_H_ 6 | 7 | typedef struct ti_str_s ti_str_t; 8 | 9 | struct ti_str_s 10 | { 11 | uint32_t ref; 12 | uint8_t tp; 13 | uint8_t unused_flags; 14 | int:16; 15 | uint32_t n; 16 | char str[]; 17 | }; 18 | 19 | 20 | #endif /* TI_STR_H_ */ 21 | -------------------------------------------------------------------------------- /inc/ti/sync.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/sync.h 3 | */ 4 | #ifndef TI_SYNC_H_ 5 | #define TI_SYNC_H_ 6 | 7 | typedef struct ti_sync_s ti_sync_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int ti_sync_create(void); 17 | int ti_sync_start(void); 18 | void ti_sync_stop(void); 19 | 20 | 21 | struct ti_sync_s 22 | { 23 | uint8_t status; 24 | uint8_t retry_offline; 25 | uv_timer_t * repeat; 26 | ti_node_t * node; 27 | }; 28 | 29 | 30 | #endif /* TI_SYNC_H_ */ 31 | -------------------------------------------------------------------------------- /inc/ti/syncarchive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/syncarchive.h 3 | */ 4 | #ifndef TI_SYNCARCHIVE_H_ 5 | #define TI_SYNCARCHIVE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_syncarchive_init(ti_stream_t * stream, uint64_t change_id); 12 | ti_pkg_t * ti_syncarchive_on_part(ti_pkg_t * pkg, ex_t * e); 13 | 14 | #endif /* TI_SYNCARCHIVE_H_ */ 15 | -------------------------------------------------------------------------------- /inc/ti/syncer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/syncer.h 3 | */ 4 | #ifndef TI_SYNCER_H_ 5 | #define TI_SYNCER_H_ 6 | 7 | typedef struct ti_syncer_s ti_syncer_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | ti_syncer_t * ti_syncer_create(ti_stream_t * stream, uint64_t first); 15 | static inline void ti_syncer_destroy(ti_syncer_t * syncer); 16 | 17 | /* extends ti_watch_t */ 18 | struct ti_syncer_s 19 | { 20 | ti_stream_t * stream; /* weak reference */ 21 | uint64_t first; /* first required change */ 22 | }; 23 | 24 | static inline void ti_syncer_destroy(ti_syncer_t * syncer) 25 | { 26 | free(syncer); 27 | } 28 | 29 | #endif /* TI_SYNCER_H_ */ 30 | -------------------------------------------------------------------------------- /inc/ti/syncevents.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/syncevents.h 3 | */ 4 | #ifndef TI_SYNCEVENTS_H_ 5 | #define TI_SYNCEVENTS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_syncevents_init(ti_stream_t * stream, uint64_t change_id); 12 | ti_pkg_t * ti_syncevents_on_part(ti_pkg_t * pkg, ex_t * e); 13 | int ti_syncevents_done(ti_stream_t * stream); 14 | 15 | #endif /* TI_SYNCEVENTS_H_ */ 16 | -------------------------------------------------------------------------------- /inc/ti/syncfull.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/syncfull.h 3 | */ 4 | #ifndef TI_SYNCFULL_H_ 5 | #define TI_SYNCFULL_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int ti_syncfull_start(ti_stream_t * stream); 12 | ti_pkg_t * ti_syncfull_on_part(ti_pkg_t * pkg, ex_t * e); 13 | 14 | #endif /* TI_FSYNC_H_ */ 15 | -------------------------------------------------------------------------------- /inc/ti/tcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/tcp.h 3 | */ 4 | #ifndef TI_TCP_H_ 5 | #define TI_TCP_H_ 6 | 7 | #include 8 | 9 | const char * ti_tcp_ip_support_str(int ip_support); 10 | int ti_tcp_ip_support_int(const char * str, int * ip_support); 11 | char * ti_tcp_name(const char * prefix, uv_tcp_t * client); 12 | int ti_tcp_addrstr(char * addr, struct addrinfo * source); 13 | int ti_tcp_addr(char * addr, uv_tcp_t * client); 14 | 15 | 16 | #endif /* TI_TCP_H_ */ 17 | -------------------------------------------------------------------------------- /inc/ti/template.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/template.h 3 | */ 4 | #ifndef TI_TEMPLATE_H_ 5 | #define TI_TEMPLATE_H_ 6 | 7 | typedef struct ti_template_s ti_template_t; 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int ti_template_build(cleri_node_t * node); 14 | int ti_template_compile(ti_template_t * tmplate, ti_query_t * query, ex_t * e); 15 | void ti_template_destroy(ti_template_t * tmplate); 16 | 17 | struct ti_template_s 18 | { 19 | uint32_t ref; 20 | uint8_t tp; 21 | uint8_t unused_flags; 22 | int:16; 23 | cleri_node_t * node; 24 | }; 25 | 26 | 27 | #endif /* TI_TEMPLATE_H_ */ 28 | -------------------------------------------------------------------------------- /inc/ti/things.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/things.h 3 | */ 4 | #ifndef TI_THINGS_H_ 5 | #define TI_THINGS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | ti_thing_t * ti_things_create_thing_o( 13 | uint64_t id, 14 | uint16_t spec, 15 | size_t init_sz, 16 | ti_collection_t * collection); 17 | ti_thing_t * ti_things_create_thing_t( 18 | uint64_t id, 19 | ti_type_t * type, 20 | ti_collection_t * collection); 21 | ti_thing_t * ti_things_thing_o_from_vup__deprecated( 22 | ti_vup_t * vup, 23 | uint64_t thing_id, 24 | size_t sz, 25 | ex_t * e); 26 | ti_thing_t * ti_things_thing_o_from_vup(ti_vup_t * vup, ex_t * e); 27 | ti_thing_t * ti_things_thing_t_from_vup(ti_vup_t * vup, ex_t * e); 28 | int ti_things_gc(imap_t * things, ti_thing_t * root); 29 | 30 | #endif /* TI_THINGS_H_ */ 31 | -------------------------------------------------------------------------------- /inc/ti/token.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/token.h 3 | */ 4 | #ifndef TI_TOKEN_H_ 5 | #define TI_TOKEN_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | ti_token_t * ti_token_create( 12 | ti_token_key_t * key, /* NULL will generate a new key */ 13 | uint64_t expire_ts, 14 | uint64_t created_at, 15 | const char * description, 16 | size_t description_sz); 17 | void ti_token_destroy(ti_token_t * token); 18 | 19 | 20 | #endif /* TI_TOKEN_H_ */ 21 | -------------------------------------------------------------------------------- /inc/ti/token.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/token.t.h 3 | */ 4 | #ifndef TI_TOKEN_T_H_ 5 | #define TI_TOKEN_T_H_ 6 | 7 | typedef struct ti_token_s ti_token_t; 8 | typedef char ti_token_key_t[22]; /* token using 22 base64 characters */ 9 | 10 | #include 11 | 12 | struct ti_token_s 13 | { 14 | ti_token_key_t key; /* contains the token key */ 15 | uint64_t expire_ts; /* 0 if not set (UNIX time in seconds) */ 16 | uint64_t created_at; /* UNIX time in seconds */ 17 | char * description; /* may be empty */ 18 | }; 19 | 20 | #endif /* TI_TOKEN_T_H_ */ 21 | -------------------------------------------------------------------------------- /inc/ti/ttask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/ttask.h (thingsdb task) 3 | */ 4 | #ifndef TI_TTASK_H_ 5 | #define TI_TTASK_H_ 6 | 7 | #include 8 | #include 9 | 10 | int ti_ttask_run(ti_change_t * change, mp_unp_t * up); 11 | 12 | #endif /* TI_RJOB_H_ */ 13 | -------------------------------------------------------------------------------- /inc/ti/types.inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/types.inline.h 3 | */ 4 | #ifndef TI_TYPES_INLINE_H_ 5 | #define TI_TYPES_INLINE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | static inline ti_type_t * ti_types_by_strn(ti_types_t * types, const char * str, size_t n) 14 | { 15 | return smap_getn(types->smap, str, n); 16 | } 17 | 18 | static inline ti_type_t * ti_types_by_raw(ti_types_t * types, ti_raw_t * raw) 19 | { 20 | return smap_getn(types->smap, (const char *) raw->data, raw->n); 21 | } 22 | 23 | static inline ti_type_t * ti_types_by_id(ti_types_t * types, uint16_t type_id) 24 | { 25 | return imap_get(types->imap, type_id); 26 | } 27 | 28 | #endif /* TI_TYPES_INLINE_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/types.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/types.t.h 3 | */ 4 | #ifndef TI_TYPES_T_H_ 5 | #define TI_TYPES_T_H_ 6 | 7 | #define TI_TYPES_RM_FLAG 0x8000 8 | #define TI_TYPES_RM_MASK 0x7fff 9 | 10 | typedef struct ti_types_s ti_types_t; 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | struct ti_types_s 18 | { 19 | imap_t * imap; 20 | smap_t * smap; 21 | smap_t * removed; /* map with type id's which are removed */ 22 | uint16_t next_id; 23 | ti_collection_t * collection; 24 | }; 25 | 26 | #endif /* TI_TYPES_T_H_ */ 27 | -------------------------------------------------------------------------------- /inc/ti/tz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/tz.h 3 | */ 4 | #ifndef TI_TZ_H_ 5 | #define TI_TZ_H_ 6 | 7 | #include 8 | #include 9 | typedef struct ti_tz_s ti_tz_t; 10 | 11 | #define TI_TZ_UTC_INDEX 0 12 | 13 | struct ti_tz_s 14 | { 15 | char * name; /* null terminated string */ 16 | size_t n; /* size excluding null terminator */ 17 | size_t index; /* index number */ 18 | }; 19 | 20 | void ti_tz_init(void); 21 | void ti_tz_set_utc(void); 22 | void ti_tz_set(ti_tz_t * tz); 23 | void ti_tz_set_offset(int16_t offset); 24 | ti_tz_t * ti_tz_utc(void); 25 | ti_tz_t * ti_tz_from_index(size_t tz_index); 26 | ti_tz_t * ti_tz_from_strn(register const char * s, register size_t n); 27 | 28 | static inline _Bool ti_tz_is_not_utc(ti_tz_t * tz) 29 | { 30 | return tz && tz->index; 31 | } 32 | 33 | ti_val_t * ti_tz_as_mpval(void); 34 | 35 | #endif /* TI_TZ_H_ */ 36 | -------------------------------------------------------------------------------- /inc/ti/vbool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vbool.h 3 | */ 4 | #ifndef TI_VBOOL_H_ 5 | #define TI_VBOOL_H_ 6 | 7 | typedef struct ti_vbool_s ti_vbool_t; 8 | 9 | #define VBOOL(__x) ((ti_vbool_t *) (__x))->bool_ 10 | 11 | #include 12 | 13 | struct ti_vbool_s 14 | { 15 | uint32_t ref; 16 | uint8_t tp; 17 | _Bool bool_; 18 | }; 19 | 20 | extern ti_vbool_t vbool__true; 21 | extern ti_vbool_t vbool__false; 22 | 23 | _Bool ti_vbool_no_ref(void); 24 | 25 | /* 26 | * This function is always successful and the result does not have to be 27 | * checked. 28 | */ 29 | static inline ti_vbool_t * ti_vbool_get(_Bool b) 30 | { 31 | ti_vbool_t * vbool = b ? &vbool__true : &vbool__false; 32 | ti_incref(vbool); 33 | return vbool; 34 | } 35 | 36 | static inline int ti_vbool_to_pk(ti_vbool_t * v, msgpack_packer * pk) 37 | { 38 | return v->bool_ ? msgpack_pack_true(pk) : msgpack_pack_false(pk); 39 | } 40 | 41 | #endif /* TI_VBOOL_H_ */ 42 | -------------------------------------------------------------------------------- /inc/ti/vfloat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vfloat.h 3 | */ 4 | #ifndef TI_VFLOAT_H_ 5 | #define TI_VFLOAT_H_ 6 | 7 | typedef struct ti_vfloat_s ti_vfloat_t; 8 | 9 | #define VFLOAT(__x) ((ti_vfloat_t *) (__x))->float_ 10 | 11 | ti_vfloat_t * ti_vfloat_create(double d); 12 | static inline void ti_vfloat_free(ti_vfloat_t * vfloat); 13 | 14 | struct ti_vfloat_s 15 | { 16 | uint32_t ref; 17 | uint8_t tp; 18 | uint8_t unused_flags; 19 | int:16; 20 | double float_; 21 | }; 22 | 23 | static inline void ti_vfloat_free(ti_vfloat_t * vfloat) 24 | { 25 | free(vfloat); 26 | } 27 | 28 | #endif /* TI_VFLOAT_H_ */ 29 | -------------------------------------------------------------------------------- /inc/ti/vint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vint.h 3 | */ 4 | #ifndef TI_VINT_H_ 5 | #define TI_VINT_H_ 6 | 7 | #include 8 | #include 9 | 10 | typedef struct ti_vint_s ti_vint_t; 11 | 12 | ti_vint_t * ti_vint_create(int64_t i); 13 | static inline void ti_vint_free(ti_vint_t * vint); 14 | _Bool ti_vint_no_ref(void); 15 | 16 | #define VINT(__x) ((ti_vint_t *) (__x))->int_ 17 | 18 | struct ti_vint_s 19 | { 20 | uint32_t ref; 21 | uint8_t tp; 22 | uint8_t unused_flags; 23 | int:16; 24 | int64_t int_; 25 | }; 26 | 27 | static inline void ti_vint_free(ti_vint_t * vint) 28 | { 29 | free(vint); 30 | } 31 | 32 | #endif /* TI_VINT_H_ */ 33 | -------------------------------------------------------------------------------- /inc/ti/vp.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vp.t.h 3 | */ 4 | #ifndef TI_VP_T_H_ 5 | #define TI_VP_T_H_ 6 | 7 | typedef struct ti_vp_s ti_vp_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_vp_s 13 | { 14 | msgpack_packer pk; 15 | ti_query_t * query; /* May be undefined; 16 | * Query must be set when the value 17 | * packer is used with `options` > 0. 18 | * Note that setting to NULL is fine 19 | * but in this case `methods` will not 20 | * be calculated. 21 | */ 22 | }; 23 | 24 | #endif /* TI_VP_T_H_ */ 25 | -------------------------------------------------------------------------------- /inc/ti/vup.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vup.t.h 3 | */ 4 | #ifndef TI_VUP_T_H_ 5 | #define TI_VUP_T_H_ 6 | 7 | typedef struct ti_vup_s ti_vup_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_vup_s 13 | { 14 | ti_collection_t * collection; 15 | mp_unp_t * up; 16 | _Bool isclient; 17 | }; 18 | 19 | #endif /* TI_VUP_T_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/watch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/watch.h 3 | * 4 | * Watch should be used as an object with at most 2 references. If no stream 5 | * attached, watch should be cleared and not in use at more than one place. 6 | */ 7 | #ifndef TI_WATCH_H_ 8 | #define TI_WATCH_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | ti_watch_t * ti_watch_create(ti_stream_t * stream); 16 | 17 | static inline void ti_watch_drop(ti_watch_t * watch) 18 | { 19 | if (watch && watch->stream) 20 | watch->stream = NULL; 21 | else 22 | free(watch); 23 | } 24 | 25 | #endif /* TI_WATCH_H_ */ 26 | -------------------------------------------------------------------------------- /inc/ti/watch.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/watch.t.h 3 | * 4 | * Watch should be used as an object with at most 2 references. If no stream 5 | * attached, watch should be cleared and not in use at more than one place. 6 | */ 7 | #ifndef TI_WATCH_T_H_ 8 | #define TI_WATCH_T_H_ 9 | 10 | typedef struct ti_watch_s ti_watch_t; 11 | 12 | #include 13 | 14 | struct ti_watch_s 15 | { 16 | ti_stream_t * stream; /* weak reference */ 17 | }; 18 | 19 | #endif /* TI_WATCH_T_H_ */ 20 | -------------------------------------------------------------------------------- /inc/ti/web.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/web.h 3 | */ 4 | #ifndef TI_WEB_H_ 5 | #define TI_WEB_H_ 6 | 7 | #include 8 | #include 9 | 10 | #define TI_WEB_IDENTIFIER UINT32_MAX; 11 | 12 | typedef struct ti_web_request_s ti_web_request_t; 13 | 14 | int ti_web_init(void); 15 | void ti_web_close(ti_web_request_t * web_request); 16 | static inline _Bool ti_web_is_handle(uv_handle_t * handle); 17 | 18 | struct ti_web_request_s 19 | { 20 | uint32_t id; /* set to TI_WEB_IDENTIFIER */ 21 | _Bool is_closed; 22 | uv_write_t req; 23 | uv_stream_t uvstream; 24 | http_parser parser; 25 | uv_buf_t * response; 26 | }; 27 | 28 | static inline _Bool ti_web_is_handle(uv_handle_t * handle) 29 | { 30 | return 31 | handle->type == UV_TCP && 32 | handle->data && 33 | ((ti_web_request_t *) handle->data)->id == TI_WEB_IDENTIFIER; 34 | } 35 | 36 | #endif /* TI_WEB_H_ */ 37 | -------------------------------------------------------------------------------- /inc/ti/whitelist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/whitelist.h 3 | */ 4 | #ifndef TI_WHITELIST_H_ 5 | #define TI_WHITELIST_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /* Do NOT CHANGE the order as this is used and stored in tasks */ 14 | enum 15 | { 16 | TI_WHITELIST_ROOMS, /* 0 */ 17 | TI_WHITELIST_PROCEDURES, /* 1 */ 18 | }; 19 | 20 | int ti_whitelist_add(vec_t ** whitelist, ti_val_t * val, ex_t * e); 21 | int ti_whitelist_del(vec_t ** whitelist, ti_val_t * val, ex_t * e); 22 | int ti_whitelist_from_strn(const char * str, size_t n, ex_t * e); 23 | int ti_whitelist_test(vec_t * whitelist, ti_name_t * name, ex_t * e); 24 | int ti_whitelist_check(vec_t * whitelist, ti_name_t * name); 25 | 26 | #endif /* TI_WHITELIST_H_ */ 27 | -------------------------------------------------------------------------------- /inc/ti/witem.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/witem.t.h 3 | */ 4 | #ifndef TI_WITEM_T_H_ 5 | #define TI_WITEM_T_H_ 6 | 7 | typedef struct ti_witem_s ti_witem_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_witem_s 13 | { 14 | ti_raw_t * key; /* without reference */ 15 | ti_val_t ** val; /* without reference */ 16 | }; 17 | 18 | #endif /* TI_WITEM_T_H_ */ 19 | -------------------------------------------------------------------------------- /inc/ti/wprop.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/wprop.t.h 3 | */ 4 | #ifndef TI_WPROP_T_H_ 5 | #define TI_WPROP_T_H_ 6 | 7 | typedef struct ti_wprop_s ti_wprop_t; 8 | 9 | #include 10 | #include 11 | 12 | struct ti_wprop_s 13 | { 14 | ti_name_t * name; /* without reference */ 15 | ti_val_t ** val; /* without reference */ 16 | }; 17 | 18 | #endif /* TI_WPROP_T_H_ */ 19 | -------------------------------------------------------------------------------- /inc/ti/wrap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/wrap.h 3 | */ 4 | #ifndef TI_WRAP_H_ 5 | #define TI_WRAP_H_ 6 | 7 | typedef struct ti_wrap_s ti_wrap_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | ti_wrap_t * ti_wrap_create(ti_thing_t * thing, uint16_t type_id); 15 | void ti_wrap_destroy(ti_wrap_t * wrap); 16 | int ti__wrap_field_thing( 17 | ti_thing_t * thing, 18 | ti_vp_t * vp, 19 | uint16_t spec, 20 | int deep, 21 | int flags); 22 | int ti_wrap_copy(ti_wrap_t ** wrap, uint8_t deep); 23 | int ti_wrap_dup(ti_wrap_t ** wrap, uint8_t deep); 24 | 25 | struct ti_wrap_s 26 | { 27 | uint32_t ref; 28 | uint8_t tp; 29 | uint8_t unused_flags; 30 | uint16_t type_id; 31 | ti_thing_t * thing; /* with reference */ 32 | }; 33 | 34 | 35 | 36 | #endif /* TI_WRAP_H_ */ 37 | -------------------------------------------------------------------------------- /inc/ti/write.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/write.h 3 | */ 4 | #ifndef TI_WRITE_H_ 5 | #define TI_WRITE_H_ 6 | 7 | typedef struct ti_write_s ti_write_t; 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | typedef void (*ti_write_cb)(ti_write_t * req, ex_enum status); 15 | 16 | int ti_write( 17 | ti_stream_t * stream, 18 | ti_pkg_t * pkg, 19 | void * data, 20 | ti_write_cb cb); 21 | void ti_write_destroy(ti_write_t * req); 22 | 23 | struct ti_write_s 24 | { 25 | ti_stream_t * stream; 26 | ti_pkg_t * pkg; 27 | void * data; 28 | ti_write_cb cb_; 29 | uv_write_t req_; 30 | }; 31 | 32 | #endif /* TI_WRITE_H_ */ 33 | -------------------------------------------------------------------------------- /inc/ti/ws.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/ws.h 3 | */ 4 | #ifndef TI_WS_H_ 5 | #define TI_WS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | int ti_ws_init(void); 14 | int ti_ws_write(ti_ws_t * pss, ti_write_t * req); 15 | char * ti_ws_name(const char * prefix, ti_ws_t * pss); 16 | void ti_ws_destroy(void); 17 | 18 | #endif /* TI_WS_H_ */ 19 | -------------------------------------------------------------------------------- /inc/ti/ws.t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/ws.t.h 3 | */ 4 | #ifndef TI_WS_T_H_ 5 | #define TI_WS_T_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct ti_ws_s ti_ws_t; 12 | 13 | struct ti_ws_s 14 | { 15 | queue_t * queue; /* ti_write_t */ 16 | ti_stream_t * stream; 17 | struct lws * wsi; 18 | size_t f; /* current frame */ 19 | size_t nf; /* total number of frames */ 20 | size_t n; /* total size to send */ 21 | }; 22 | 23 | #endif /* TI_WS_T_H_ */ 24 | -------------------------------------------------------------------------------- /inc/util/buf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util/buf.h 3 | */ 4 | #ifndef BUF_H_ 5 | #define BUF_H_ 6 | 7 | #include 8 | #include 9 | 10 | typedef struct buf_s buf_t; 11 | 12 | void buf_init(buf_t * buf); 13 | int buf_append(buf_t * buf, const char * s, size_t n); 14 | int buf_write(buf_t * buf, const char c); 15 | 16 | #define buf_append_str(buf__, s__) \ 17 | buf_append(buf__, s__, strlen(s__)) 18 | 19 | int buf_append_fmt(buf_t * buf, const char * s, ...); 20 | 21 | struct buf_s 22 | { 23 | size_t cap; 24 | size_t len; 25 | char * data; 26 | }; 27 | 28 | #endif /* BUF_H_ */ 29 | -------------------------------------------------------------------------------- /inc/util/cryptx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util/cryptx.h 3 | */ 4 | #ifndef CRYPTX_H_ 5 | #define CRYPTX_H_ 6 | 7 | #define CRYPTX_SZ 64 8 | #define CRYPTX_SALT_SZ 10 9 | 10 | void cryptx(const char * password, const char * salt, char * encrypted); 11 | void cryptx_gen_salt(char * salt); 12 | 13 | #endif /* CRYPTX_H_ */ 14 | -------------------------------------------------------------------------------- /inc/util/guid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * guid.h 3 | */ 4 | #ifndef GUID_H_ 5 | #define GUID_H_ 6 | 7 | typedef struct guid_s guid_t; 8 | 9 | #include 10 | 11 | void guid_init(guid_t * guid, uint64_t id); 12 | 13 | struct guid_s 14 | { 15 | char guid[12]; 16 | }; 17 | 18 | #endif /* GUID_H_ */ 19 | 20 | -------------------------------------------------------------------------------- /inc/util/iso8601.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util/iso8601.h - parse ISO 8601 dates. 3 | */ 4 | #ifndef ISO8601_H_ 5 | #define ISO8601_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* 12 | * Returns a time-stamp in seconds for a given date or a negative value in 13 | * case of an error. 14 | */ 15 | int64_t iso8601_parse_date(const char * str); 16 | int64_t iso8601_parse_date_n(const char * str, size_t n); 17 | 18 | #endif /* ISO8601_H_ */ 19 | -------------------------------------------------------------------------------- /inc/util/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lock.h 3 | */ 4 | #ifndef LOCK_H_ 5 | #define LOCK_H_ 6 | 7 | #define LOCK_FLAG_OVERWRITE 1 8 | 9 | typedef enum 10 | { 11 | LOCK_IS_LOCKED_ERR=-6, 12 | LOCK_PROCESS_NAME_ERR, 13 | LOCK_WRITE_ERR, 14 | LOCK_READ_ERR, 15 | LOCK_UNLINK_ERR, 16 | LOCK_MEM_ALLOC_ERR, 17 | LOCK_REMOVED=0, 18 | LOCK_NEW, 19 | LOCK_OVERWRITE 20 | } lock_t; 21 | 22 | lock_t lock_lock(const char * path, int flags); 23 | lock_t lock_unlock(const char * path); 24 | const char * lock_str(lock_t rc); 25 | 26 | #endif /* LOCK_H_ */ 27 | -------------------------------------------------------------------------------- /inc/util/osarch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util/osarch.h 3 | */ 4 | #ifndef UTIL_OSARCH_H_ 5 | #define UTIL_OSARCH_H_ 6 | 7 | void osarch_init(void); /* initialize */ 8 | const char * osarch_get_os(void); /* example: linux */ 9 | const char * osarch_get_arch(void); /* example: amd64 */ 10 | const char * osarch_get(void); /* example: linux/amd64 */ 11 | 12 | #endif /* UTIL_OSARCH_H_ */ 13 | -------------------------------------------------------------------------------- /inc/util/rbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util/rbuf.h 3 | */ 4 | #ifndef RBUF_H_ 5 | #define RBUF_H_ 6 | 7 | #include 8 | #include 9 | 10 | typedef struct rbuf_s rbuf_t; 11 | 12 | void rbuf_init(rbuf_t * buf); 13 | int rbuf_append(rbuf_t * buf, const char * s, size_t n); 14 | int rbuf_write(rbuf_t * buf, const char c); 15 | 16 | struct rbuf_s 17 | { 18 | size_t pos; 19 | size_t cap; 20 | char * data; 21 | }; 22 | 23 | #define rbuf_len(__rbuf) ((__rbuf)->cap - (__rbuf)->pos) 24 | 25 | #endif /* RBUF_H_ */ 26 | -------------------------------------------------------------------------------- /inc/util/syncpart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * syncpart.h 3 | */ 4 | #ifndef SYNCPART_H_ 5 | #define SYNCPART_H_ 6 | 7 | #include 8 | #include 9 | 10 | #ifndef SYNCPART_SIZE 11 | #define SYNCPART_SIZE 131072UL 12 | #endif 13 | 14 | int syncpart_to_pk(msgpack_packer * pk, const char * fn, off_t offset); 15 | 16 | int syncpart_write( 17 | const char * fn, 18 | const unsigned char * data, 19 | size_t size, 20 | off_t offset, 21 | ex_t * e); 22 | 23 | #endif /* SYNCPART_H_ */ 24 | -------------------------------------------------------------------------------- /itest/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python AS builder 2 | RUN apt-get update && \ 3 | apt-get install -y \ 4 | libuv1-dev \ 5 | libpcre2-dev \ 6 | libyajl-dev \ 7 | libcurl4-nss-dev \ 8 | build-essential \ 9 | cmake 10 | WORKDIR /opt 11 | COPY ./CMakeLists.txt ./CMakeLists.txt 12 | COPY ./main.c ./main.c 13 | COPY ./src/ ./src/ 14 | COPY ./inc/ ./inc/ 15 | COPY ./libwebsockets/ ./libwebsockets/ 16 | RUN cmake -DCMAKE_BUILD_TYPE=Debug . && make 17 | 18 | FROM python 19 | RUN apt-get update && \ 20 | apt-get install -y \ 21 | valgrind \ 22 | libuv1 \ 23 | libpcre2-8-0 \ 24 | libyajl2 \ 25 | libcurl3-nss 26 | COPY --from=builder ./opt/thingsdb /thingsdb 27 | COPY ./itest/ /itest/ 28 | COPY ./inc/doc.h /inc/doc.h 29 | COPY ./memleak.supp /memleak.supp 30 | WORKDIR /itest 31 | RUN pip install -r requirements.txt 32 | ENV THINGSDB_BIN=/thingsdb 33 | CMD [ "python", "run_all_tests.py" ] 34 | -------------------------------------------------------------------------------- /itest/lib/cleanup.py: -------------------------------------------------------------------------------- 1 | import os 2 | import logging 3 | import shutil 4 | from .vars import THINGSDB_TESTDIR 5 | 6 | 7 | def cleanup(): 8 | logging.info('Remove test dir') 9 | try: 10 | shutil.rmtree(os.path.join(THINGSDB_TESTDIR)) 11 | except FileNotFoundError: 12 | pass 13 | os.mkdir(THINGSDB_TESTDIR) 14 | killall() 15 | 16 | 17 | def killall(): 18 | logging.info('Force kill all open thingsdb processes') 19 | os.system('pkill -9 thingsdb') 20 | 21 | logging.info('Force kill all open memcheck-amd64- processes') 22 | os.system('pkill -9 memcheck-amd64-') 23 | -------------------------------------------------------------------------------- /itest/lib/client.py: -------------------------------------------------------------------------------- 1 | from thingsdb.client import Client 2 | 3 | 4 | async def get_client( 5 | *nodes, 6 | auth=['admin', 'pass'], 7 | auto_reconnect=True, 8 | **kwargs): 9 | client = Client( 10 | auto_reconnect=auto_reconnect, 11 | ssl=nodes[0].use_ssl, 12 | **kwargs) 13 | if isinstance(auth, str): 14 | auth = [auth] 15 | if auto_reconnect: 16 | await client.connect_pool( 17 | [node.address_info for node in nodes], 18 | *auth) 19 | else: 20 | await client.connect(*nodes[0].address_info) 21 | await client.authenticate(*auth) 22 | return client 23 | -------------------------------------------------------------------------------- /itest/lib/color.py: -------------------------------------------------------------------------------- 1 | 2 | NORMAL = '\x1B[0m' 3 | RED = '\x1B[31m' 4 | GREEN = '\x1B[32m' 5 | YELLOW = '\x1B[33m' 6 | LYELLOW = '\x1b[93m' 7 | 8 | BGRED = "\x1b[41m" 9 | BGGREEN = "\x1b[42m" 10 | BGYELLOW = "\x1b[43m" 11 | BGBLUE = "\x1b[44m" 12 | BGMAGENTA = "\x1b[45m" 13 | BGCYAN = "\x1b[46m" 14 | BGWHITE = "\x1b[47m" 15 | 16 | 17 | class Color: 18 | 19 | @staticmethod 20 | def success(text): 21 | return f'{GREEN}{text}{NORMAL}' 22 | 23 | @staticmethod 24 | def warning(text): 25 | return f'{YELLOW}{text}{NORMAL}' 26 | 27 | @staticmethod 28 | def error(text): 29 | return f'{RED}{text}{NORMAL}' 30 | 31 | @staticmethod 32 | def info(text): 33 | return f'{LYELLOW}{text}{NORMAL}' 34 | 35 | @staticmethod 36 | def node(n, text): 37 | color = [BGRED, BGMAGENTA, BGBLUE, BGCYAN, BGGREEN, BGYELLOW][n] 38 | return f'{color}NODE {n}{NORMAL}: {text}' 39 | -------------------------------------------------------------------------------- /itest/lib/spinner.py: -------------------------------------------------------------------------------- 1 | SPINNER1 = \ 2 | ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▇', '▆', '▅', '▄', '▃', '▁') 3 | SPINNER2 = \ 4 | ('⠁', '⠂', '⠄', '⡀', '⢀', '⠠', '⠐', '⠈') 5 | SPINNER3 = \ 6 | ('◐', '◓', '◑', '◒') 7 | 8 | 9 | class Spinner(): 10 | 11 | def __init__(self, charset=SPINNER3): 12 | self._idx = 0 13 | self._charset = charset 14 | self._len = len(charset) 15 | 16 | @property 17 | def next(self): 18 | char = self._charset[self._idx] 19 | self._idx += 1 20 | self._idx %= self._len 21 | return char 22 | -------------------------------------------------------------------------------- /itest/lib/target.py: -------------------------------------------------------------------------------- 1 | from thingsdb.client import Client 2 | from thingsdb.scope import Scope 3 | 4 | 5 | async def create_target(client: Client, name: str): 6 | target = Scope(name) 7 | await client.new_collection(target) 8 | return target 9 | -------------------------------------------------------------------------------- /itest/requirements.txt: -------------------------------------------------------------------------------- 1 | psutil 2 | pycodestyle 3 | msgpack 4 | python-thingsdb 5 | requests 6 | pytz 7 | websockets 8 | -------------------------------------------------------------------------------- /itest/slow_network_test.sh: -------------------------------------------------------------------------------- 1 | #Refer: http://www.linuxfoundation.org/collaborate/workgroups/networking/netem#Delaying_only_some_traffic 2 | #Refer: http://www.bomisofmab.com/blog/?p=100 3 | #Refer: http://drija.com/linux/41983/simulating-a-low-bandwidth-high-latency-network-connection-on-linux/ 4 | 5 | #Setup the rate control and delay 6 | sudo tc qdisc add dev lo root handle 1: htb default 12 7 | sudo tc class add dev lo parent 1:1 classid 1:12 htb rate 56kbps ceil 128kbps 8 | sudo tc qdisc add dev lo parent 1:12 netem delay 200ms 9 | 10 | #Remove the rate control/delay 11 | sudo tc qdisc del dev lo root 12 | 13 | #To see what is configured on an interface, do this 14 | sudo tc -s qdisc ls dev lo 15 | 16 | #Replace lo with eth0/wlan0 to limit speed from wide lan 17 | -------------------------------------------------------------------------------- /itest/ws/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /libwebsockets/Makefile.projbuild: -------------------------------------------------------------------------------- 1 | CPPFLAGS += -I$(BUILD_DIR_BASE)/libwebsockets/include 2 | -------------------------------------------------------------------------------- /libwebsockets/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | If you become aware of an issue with lws that has a security dimension for users, please contact andy@warmcat.com by direct email. 4 | 5 | ## Procedure for announcing vulnerability fixes 6 | The problem and fixed versions will be announced by a note added to the main README.md. 7 | -------------------------------------------------------------------------------- /libwebsockets/cmake/libwebsockets-config-version.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@CPACK_PACKAGE_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /libwebsockets/lgtm.yml: -------------------------------------------------------------------------------- 1 | queries: 2 | - exclude: cpp/short-global-name 3 | - exclude: cpp/useless-expression 4 | -------------------------------------------------------------------------------- /libwebsockets/lib/README.md: -------------------------------------------------------------------------------- 1 | ## Library sources layout 2 | 3 | Code that goes in the libwebsockets library itself lives down ./lib 4 | 5 | Path|Sources 6 | ---|--- 7 | lib/core|Core lws code related to generic fd and wsi servicing and management 8 | lib/core-net|Core lws code that applies only if networking enabled 9 | lib/event-libs|Code containing optional event-lib specific adaptations 10 | lib/jose|JOSE / JWS / JWK / JWE implementations 11 | lib/misc|Code for various mostly optional miscellaneous features 12 | lib/plat|Platform-specific adaptation code 13 | lib/roles|Code for specific optional wsi roles, eg, http/1, h2, ws, raw, etc 14 | lib/system|Code for system-level features, eg, dhcpclient 15 | lib/tls|Code supporting the various TLS libraries 16 | 17 | -------------------------------------------------------------------------------- /libwebsockets/lib/drivers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list(APPEND SOURCES 2 | drivers/display/lws-display.c 3 | drivers/display/ssd1306-i2c.c 4 | drivers/display/ili9341-spi.c 5 | drivers/display/spd1656-spi.c 6 | drivers/display/uc8176-spi.c 7 | drivers/display/ssd1675b-spi.c 8 | drivers/i2c/lws-i2c.c 9 | drivers/i2c/bitbang/lws-bb-i2c.c 10 | drivers/spi/lws-spi.c 11 | drivers/spi/bitbang/lws-bb-spi.c 12 | drivers/button/lws-button.c 13 | drivers/led/led-gpio.c 14 | drivers/led/led-seq.c 15 | drivers/pwm/pwm.c 16 | drivers/settings/settings.c 17 | ) 18 | 19 | if (LWS_WITH_NETWORK) 20 | list(APPEND SOURCES 21 | drivers/netdev/netdev.c 22 | drivers/netdev/wifi.c) 23 | endif() 24 | 25 | if (LWS_ESP_PLATFORM) 26 | list(APPEND SOURCES 27 | plat/freertos/esp32/drivers/gpio-esp32.c 28 | plat/freertos/esp32/drivers/pwm-esp32.c 29 | ) 30 | endif() 31 | 32 | exports_to_parent_scope() 33 | 34 | -------------------------------------------------------------------------------- /libwebsockets/lib/event-libs/sdevent/private-lib-event-libs-sdevent.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern const struct lws_event_loop_ops event_loop_ops_sdevent; 4 | -------------------------------------------------------------------------------- /libwebsockets/lib/misc/fts/private-lib-misc-fts.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* if you need > 2GB trie files */ 4 | //typedef off_t jg2_file_offset; 5 | typedef uint32_t jg2_file_offset; 6 | 7 | struct lws_fts_file { 8 | int fd; 9 | jg2_file_offset root, flen, filepath_table; 10 | int max_direct_hits; 11 | int max_completion_hits; 12 | int filepaths; 13 | }; 14 | 15 | 16 | 17 | #define TRIE_FILE_HDR_SIZE 20 18 | #define MAX_VLI 5 19 | 20 | #define LWS_FTS_LINES_PER_CHUNK 200 21 | 22 | int 23 | rq32(unsigned char *b, uint32_t *d); 24 | -------------------------------------------------------------------------------- /libwebsockets/lib/roles/http/compression/README.md: -------------------------------------------------------------------------------- 1 | HTTP compression 2 | ---------------- 3 | 4 | This directory contains generic compression transforms that can be applied to 5 | specifically HTTP content streams, after the header, be it h1 or h2. 6 | 7 | The compression transforms expose an "ops" type struct and a compressor name 8 | as used by `content-encoding`... the ops struct definition can be found in 9 | ./private-lib-roles-http-compression.h. 10 | 11 | Because the compression transform depends on being able to send on its output 12 | before it can process new input, the transform adds a new kind of buflist 13 | `wsi->buflist_comp` that represents pre-compression transform data 14 | ("input data" from the perspective of the compression transform) that was 15 | delivered to be processed but couldn't be accepted. 16 | 17 | Currently, zlib 'deflate' and brotli 'br' are supported on the server side. 18 | -------------------------------------------------------------------------------- /libwebsockets/lib/secure-streams/serialized/client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(../../../core 2 | ../../../core-net 3 | ../../../plat/unix 4 | ../../../plat/freertos 5 | ../../../tls 6 | ../../../event-libs 7 | ../../../roles 8 | ../../../roles/http 9 | ../../../roles/h1 10 | ../../../roles/h2 11 | ../../../roles/ws 12 | ../../../roles/mqtt 13 | ../../../roles/raw 14 | 15 | ../../../system 16 | ../../../system/smd 17 | ../../../system/fault-injection 18 | ../../../system/metrics 19 | 20 | ${LIBUV_INCLUDE_DIRS} 21 | ) 22 | 23 | 24 | foreach(libpath ${LWS_LIB_BUILD_INC_PATHS}) 25 | include_directories(${libpath}) 26 | endforeach() 27 | 28 | -------------------------------------------------------------------------------- /libwebsockets/lib/system/metrics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | if (LWS_WITH_SYS_METRICS) 4 | list(APPEND SOURCES 5 | system/metrics/metrics.c 6 | ) 7 | endif() 8 | 9 | exports_to_parent_scope() 10 | 11 | -------------------------------------------------------------------------------- /libwebsockets/lib/system/smd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | list(APPEND SOURCES 4 | system/smd/smd.c 5 | ) 6 | 7 | exports_to_parent_scope() 8 | 9 | -------------------------------------------------------------------------------- /libwebsockets/lwsws/etc-logrotate.d-lwsws: -------------------------------------------------------------------------------- 1 | /var/log/lwsws/*log { 2 | copytruncate 3 | missingok 4 | notifempty 5 | delaycompress 6 | postrotate 7 | /bin/systemctl reload lwsws.service > /dev/null 2>/dev/null || true 8 | endscript 9 | } 10 | 11 | -------------------------------------------------------------------------------- /libwebsockets/lwsws/etc-lwsws-conf-EXAMPLE: -------------------------------------------------------------------------------- 1 | # these are the server global settings 2 | # stuff related to vhosts should go in one 3 | # file per vhost in ../conf.d/ 4 | 5 | { 6 | "global": { 7 | "uid": "48", 8 | "gid": "48", 9 | "interface": "eth0", 10 | "count-threads": "1", 11 | "server-string": "lwsws", 12 | "ws-pingpong-secs": "200", 13 | "init-ssl": "yes" 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /libwebsockets/lwsws/usr-lib-systemd-system-lwsws.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Libwebsockets Web Server 3 | After=syslog.target 4 | 5 | [Service] 6 | ExecStart=/usr/local/bin/lwsws 7 | ExecReload=/usr/bin/kill -HUP $MAINPID 8 | ExecStop=/usr/bin/killall lwsws 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | 13 | -------------------------------------------------------------------------------- /libwebsockets/plugins/lwsws-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thingsdb/ThingsDB/bda6ba4c584f2b73066f4b93fe6f352454ef4ad0/libwebsockets/plugins/lwsws-logo.png -------------------------------------------------------------------------------- /libwebsockets/plugins/ssh-base/include/lws-plugin-sshd-static-build-includes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * If you are including the plugin into your code using static build, you 3 | * can simplify it by just including this file, which will include all the 4 | * related code in one step without you having to get involved in the detail. 5 | */ 6 | 7 | #define LWS_PLUGIN_STATIC 8 | 9 | #include "../crypto/chacha.c" 10 | #include "../crypto/ed25519.c" 11 | #include "../crypto/fe25519.c" 12 | #include "../crypto/ge25519.c" 13 | #include "../crypto/poly1305.c" 14 | #include "../crypto/sc25519.c" 15 | #include "../crypto/smult_curve25519_ref.c" 16 | #include "../kex-25519.c" 17 | #include "../sshd.c" 18 | #include "../telnet.c" 19 | -------------------------------------------------------------------------------- /misc/Keraleeyam-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thingsdb/ThingsDB/bda6ba4c584f2b73066f4b93fe6f352454ef4ad0/misc/Keraleeyam-Regular.ttf -------------------------------------------------------------------------------- /release-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd "$(dirname "$0")" 3 | cmake -DCMAKE_BUILD_TYPE=Release . 4 | make 5 | -------------------------------------------------------------------------------- /src/cleri/dup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dup.c - this cleri element can be used to duplicate an element. 3 | */ 4 | #include 5 | 6 | static void dup__free(cleri_t * cl_object); 7 | 8 | /* 9 | * Duplicate a libcleri object. 10 | * Note: a pointer to the original object->via (element) is used. 11 | */ 12 | cleri_t * cleri_dup(uint32_t gid, cleri_t * cl_obj) 13 | { 14 | cleri_dup_t * dup = cleri__malloc(cleri_dup_t); 15 | if (dup != NULL) 16 | { 17 | dup->gid = gid; 18 | dup->ref = 1; 19 | dup->tp = cl_obj->tp; 20 | dup->via = cl_obj->via; 21 | dup->free_object = &dup__free; 22 | dup->parse_object = cl_obj->parse_object; 23 | cleri_incref(cl_obj); 24 | dup->dup = cl_obj; 25 | } 26 | return (cleri_t *) dup; 27 | } 28 | 29 | static void dup__free(cleri_t * cl_object) 30 | { 31 | cleri_dup_t * dup = (cleri_dup_t *) cl_object; 32 | cleri_free(dup->dup); 33 | } 34 | -------------------------------------------------------------------------------- /src/cleri/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * version.c - cleri version information. 3 | */ 4 | 5 | #include 6 | 7 | const char * cleri_version(void) 8 | { 9 | return LIBCLERI_VERSION; 10 | } -------------------------------------------------------------------------------- /src/ti/deep.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | int ti_deep_from_val(ti_val_t * val, uint8_t * deep, ex_t * e) 9 | { 10 | int64_t deepi; 11 | 12 | if (!ti_val_is_int(val)) 13 | { 14 | ex_set(e, EX_TYPE_ERROR, 15 | "expecting `deep` to be of type `"TI_VAL_INT_S"` " 16 | "but got type `%s` instead", 17 | ti_val_str(val)); 18 | return e->nr; 19 | } 20 | 21 | deepi = VINT(val); 22 | 23 | if (deepi < 0 || deepi > TI_MAX_DEEP) 24 | { 25 | ex_set(e, EX_VALUE_ERROR, 26 | "expecting a `deep` value between 0 and %d " 27 | "but got %"PRId64" instead", 28 | TI_MAX_DEEP, deepi); 29 | return e->nr; 30 | } 31 | 32 | *deep = (uint8_t) deepi; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/ti/flags.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | int ti_flags_set_from_val(ti_val_t * val, uint8_t * flags, ex_t * e) 9 | { 10 | if (!ti_val_is_int(val)) 11 | { 12 | ex_set(e, EX_TYPE_ERROR, 13 | "expecting `flags` to be of type `"TI_VAL_INT_S"` " 14 | "but got type `%s` instead", 15 | ti_val_str(val)); 16 | return e->nr; 17 | } 18 | 19 | *flags |= VINT(val) & TI_FLAGS_NO_IDS; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/ti/fn.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fn_arg_str_slow( 4 | const char * name, 5 | const char * doc, 6 | int argn, 7 | ti_val_t * val, 8 | ex_t * e) 9 | { 10 | if (!ti_val_is_str(val)) 11 | ex_set(e, EX_TYPE_ERROR, 12 | "function `%s` expects argument %d to be of " 13 | "type `"TI_VAL_STR_S"` but got type `%s` instead%s", 14 | name, argn, ti_val_str(val), doc); 15 | return e->nr; 16 | } 17 | -------------------------------------------------------------------------------- /src/ti/fwd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/fwd.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | ti_fwd_t * ti_fwd_create(uint16_t orig_pkg_id, ti_stream_t * src_stream) 10 | { 11 | ti_fwd_t * fwd = malloc(sizeof(ti_fwd_t)); 12 | if (!fwd) 13 | return NULL; 14 | fwd->orig_pkg_id = orig_pkg_id; 15 | fwd->dummy = 0; /* MUST be set to 0 for casting */ 16 | fwd->stream = ti_grab(src_stream); 17 | return fwd; 18 | } 19 | 20 | void ti_fwd_destroy(ti_fwd_t * fwd) 21 | { 22 | if (!fwd) 23 | return; 24 | ti_stream_drop(fwd->stream); 25 | free(fwd); 26 | } 27 | -------------------------------------------------------------------------------- /src/ti/gc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/gc.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | ti_gc_t * ti_gc_create(uint64_t change_id, ti_thing_t * thing) 9 | { 10 | ti_gc_t * gc = malloc(sizeof(ti_gc_t)); 11 | if (!gc) 12 | return NULL; 13 | 14 | gc->change_id = change_id; 15 | gc->thing = thing; 16 | 17 | ti_incref(thing); 18 | 19 | return gc; 20 | } 21 | 22 | void ti_gc_destroy(ti_gc_t * gc) 23 | { 24 | if (!gc) 25 | return; 26 | ti_val_unsafe_drop((ti_val_t *) gc->thing); 27 | free(gc); 28 | } 29 | -------------------------------------------------------------------------------- /src/ti/mapping.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mapping.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | ti_mapping_t * ti_mapping_new(ti_field_t * t_field, ti_field_t * f_field) 9 | { 10 | ti_mapping_t * mapping = malloc(sizeof(ti_mapping_t)); 11 | if (!mapping) 12 | return NULL; 13 | 14 | mapping->t_field = t_field; 15 | mapping->f_field = f_field; 16 | return mapping; 17 | } 18 | -------------------------------------------------------------------------------- /src/ti/mod/work.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/mod/work.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | void ti_mod_work_destroy(ti_mod_work_t * data) 9 | { 10 | ti_mod_manifest_clear(&data->manifest); 11 | ti_module_drop(data->module); 12 | free(data->buf.data); 13 | free(data); 14 | } 15 | -------------------------------------------------------------------------------- /src/ti/nil.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | ti_nil_t nil__val = { 7 | .ref = 1, 8 | .tp = TI_VAL_NIL, 9 | .nil = NULL, 10 | }; 11 | -------------------------------------------------------------------------------- /src/ti/pipe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/pipe.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | * Return a name for the connection if successful or NULL in case of a failure. 11 | * 12 | * The returned value is malloced and should be freed. 13 | */ 14 | char * ti_pipe_name(const char * prefix, uv_pipe_t * client) 15 | { 16 | size_t n = strlen(prefix); 17 | size_t len = FX_PATH_MAX - 1; 18 | char * buffer = malloc(FX_PATH_MAX + n); 19 | 20 | if (buffer == NULL || uv_pipe_getsockname(client, buffer + n, &len)) 21 | { 22 | free(buffer); 23 | return NULL; 24 | } 25 | 26 | memcpy(buffer, prefix, n); 27 | 28 | buffer[len] = '\0'; 29 | return buffer; 30 | } 31 | -------------------------------------------------------------------------------- /src/ti/rooms.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/rooms.c 3 | */ 4 | 5 | #include 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/ti/rpkg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/rpkg.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | ti_rpkg_t * ti_rpkg_create(ti_pkg_t * pkg) 9 | { 10 | ti_rpkg_t * rpkg = malloc(sizeof(ti_rpkg_t)); 11 | if (!rpkg) 12 | return NULL; 13 | rpkg->ref = 1; 14 | rpkg->pkg = pkg; 15 | return rpkg; 16 | } 17 | 18 | void ti_rpkg_drop(ti_rpkg_t * rpkg) 19 | { 20 | if (rpkg && !--rpkg->ref) 21 | { 22 | free(rpkg->pkg); 23 | free(rpkg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/ti/syncer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/syncer.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | ti_syncer_t * ti_syncer_create(ti_stream_t * stream, uint64_t first) 10 | { 11 | ti_syncer_t * syncer = malloc(sizeof(ti_syncer_t)); 12 | if (!syncer) 13 | return NULL; 14 | 15 | syncer->stream = stream; 16 | syncer->first = first; 17 | 18 | return syncer; 19 | } 20 | -------------------------------------------------------------------------------- /src/ti/vbool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vbool.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | ti_vbool_t vbool__true = { 10 | .ref = 1, 11 | .tp = TI_VAL_BOOL, 12 | .bool_ = true, 13 | }; 14 | 15 | ti_vbool_t vbool__false = { 16 | .ref = 1, 17 | .tp = TI_VAL_BOOL, 18 | .bool_ = false, 19 | }; 20 | 21 | /* 22 | * Can be used for a sanity check when stopping ThingsDB to see if all 23 | * references are cleared. 24 | */ 25 | _Bool ti_vbool_no_ref(void) 26 | { 27 | return vbool__true.ref == 1 && vbool__false.ref == 1; 28 | } 29 | -------------------------------------------------------------------------------- /src/ti/vfloat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/vfloat.c 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static ti_vfloat_t vfloat__0 = { 10 | .ref = 1, 11 | .tp = TI_VAL_FLOAT, 12 | .float_ = 0.0, 13 | }; 14 | 15 | ti_vfloat_t * ti_vfloat_create(double d) 16 | { 17 | ti_vfloat_t * vfloat; 18 | if (!d) 19 | { 20 | vfloat = &vfloat__0; 21 | ti_incref(vfloat); 22 | return vfloat; 23 | } 24 | 25 | vfloat = malloc(sizeof(ti_vfloat_t)); 26 | if (!vfloat) 27 | return NULL; 28 | 29 | vfloat->ref = 1; 30 | vfloat->tp = TI_VAL_FLOAT; 31 | vfloat->float_ = d; 32 | 33 | return vfloat; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/ti/watch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ti/watch.h 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | ti_watch_t * ti_watch_create(ti_stream_t * stream) 13 | { 14 | ti_watch_t * watch = malloc(sizeof(ti_watch_t)); 15 | if (!watch) 16 | return NULL; 17 | watch->stream = stream; 18 | return watch; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/util/guid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * guid.c 3 | */ 4 | #include 5 | #include 6 | 7 | static const char guid__map[64] = { 8 | '0', '1', '2', '3', '4', '5', '6', '7', 9 | '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 10 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 11 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 12 | 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 13 | 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 14 | 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 15 | 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '_' 16 | }; 17 | 18 | void guid_init(guid_t * guid, uint64_t id) 19 | { 20 | char * pt = guid->guid; 21 | 22 | for (uint64_t i = 60; i >= 6; i -= 6, pt++) 23 | { 24 | *pt = guid__map[id / ((uint64_t) 1 << i)]; 25 | id %= (uint64_t) 1 << i; 26 | } 27 | 28 | *pt = guid__map[id]; 29 | pt++; 30 | *pt = '\0'; 31 | } 32 | -------------------------------------------------------------------------------- /test/_test_big/sources: -------------------------------------------------------------------------------- 1 | ../src/util/big.c -------------------------------------------------------------------------------- /test/_test_lookup/sources: -------------------------------------------------------------------------------- 1 | ../src/ti/lookup.c 2 | ../src/util/vec.c -------------------------------------------------------------------------------- /test/test_guid/sources: -------------------------------------------------------------------------------- 1 | ../src/util/guid.c -------------------------------------------------------------------------------- /test/test_guid/test_guid.c: -------------------------------------------------------------------------------- 1 | #include "../test.h" 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | test_start("guid"); 8 | 9 | /* test guid */ 10 | { 11 | guid_t guid; 12 | 13 | guid_init(&guid, 1); 14 | _assert ( guid.guid[sizeof(guid_t) - 1] == '\0'); 15 | 16 | guid_init(&guid, ((uint64_t) 1 << 63) - 1); 17 | _assert ( strcmp(guid.guid, "7__________") == 0); 18 | 19 | guid_init(&guid, 0); 20 | _assert ( strcmp(guid.guid, "00000000000") == 0); 21 | 22 | guid_init(&guid, 63); 23 | _assert ( strcmp(guid.guid, "0000000000_") == 0); 24 | 25 | guid_init(&guid, 64); 26 | _assert ( strcmp(guid.guid, "00000000010") == 0); 27 | 28 | } 29 | 30 | return test_end(); 31 | } 32 | -------------------------------------------------------------------------------- /test/test_imap/sources: -------------------------------------------------------------------------------- 1 | ../src/util/imap.c 2 | ../src/util/vec.c -------------------------------------------------------------------------------- /test/test_link/sources: -------------------------------------------------------------------------------- 1 | ../src/util/link.c -------------------------------------------------------------------------------- /test/test_omap/sources: -------------------------------------------------------------------------------- 1 | ../src/util/omap.c -------------------------------------------------------------------------------- /test/test_queue/sources: -------------------------------------------------------------------------------- 1 | ../src/util/queue.c 2 | ../src/util/vec.c -------------------------------------------------------------------------------- /test/test_smap/sources: -------------------------------------------------------------------------------- 1 | ../src/util/smap.c 2 | ../src/util/logger.c -------------------------------------------------------------------------------- /test/test_strx/sources: -------------------------------------------------------------------------------- 1 | ../src/util/strx.c 2 | -------------------------------------------------------------------------------- /test/test_vec/sources: -------------------------------------------------------------------------------- 1 | ../src/util/vec.c --------------------------------------------------------------------------------