diff options
-rw-r--r-- | .github/workflows/build.yml | 1 | ||||
-rw-r--r-- | python/DEV_GUIDE.md | 29 | ||||
-rw-r--r-- | python/README.md | 1 | ||||
-rw-r--r-- | python/ndpi/__init__.py | 2 | ||||
-rw-r--r-- | python/ndpi/ndpi.py | 16 |
5 files changed, 40 insertions, 9 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8d35dd0f..63f0b0431 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,6 +62,7 @@ jobs: run: | env CC=gcc CFLAGS='-Werror' ./autogen.sh make + sudo make install - name: Generate Python bindings run: | cd python diff --git a/python/DEV_GUIDE.md b/python/DEV_GUIDE.md new file mode 100644 index 000000000..4003ca08e --- /dev/null +++ b/python/DEV_GUIDE.md @@ -0,0 +1,29 @@ +# Python Bindings Development Guide + +The aim of this document is to guide when extending these bindings with additional nDPI API. +In the following we suppose that we want to add the following API to ndpi python package. + +``` c +int ndpi_des_init(struct ndpi_des_struct *des, double alpha, double beta, float significance); +``` + +## Add it to NDPI_APIS Python definition + + +[**NDPI_APIS**][py_ndpi_api] must be updated with the this new API your want to add. + + +## That's it! + +Now this API can be called and used on python side + +``` python +from ndpi import, lib, ffi + +des = ffi.new("struct ndpi_des_struct *") +alpha = 0.9 +beta = 0.5 +lib.ndpi_des_init(des, alpha, beta, 0.05) +``` + +[py_ndpi_api]: https://github.com/ntop/nDPI/blob/c47d710d8e5281fff2f1f90ff5462c16ac91d50c/python/ndpi/ndpi_build.py#L49
\ No newline at end of file diff --git a/python/README.md b/python/README.md index 8cb2f64c6..695874fd1 100644 --- a/python/README.md +++ b/python/README.md @@ -15,6 +15,7 @@ cd nDPI ./autogen.sh ./configure make +sudo make install ``` ### Install ndpi package diff --git a/python/ndpi/__init__.py b/python/ndpi/__init__.py index f6f5b9079..d97d9047f 100644 --- a/python/ndpi/__init__.py +++ b/python/ndpi/__init__.py @@ -13,7 +13,7 @@ If not, see <http://www.gnu.org/licenses/>. ------------------------------------------------------------------------------------------------------------------------ """ -from .ndpi import NDPI, NDPIFlow +from .ndpi import * __author__ = """Zied Aouini""" diff --git a/python/ndpi/ndpi.py b/python/ndpi/ndpi.py index 0dd5b56cf..4a7cf5f56 100644 --- a/python/ndpi/ndpi.py +++ b/python/ndpi/ndpi.py @@ -47,7 +47,7 @@ class NDPI(object): def process_packet(self, flow, packet, packet_time_ms): p = lib.ndpi_detection_process_packet(self._detection_module, - flow._C, + flow.C, packet, len(packet), int(packet_time_ms)) @@ -58,7 +58,7 @@ class NDPI(object): def giveup(self, flow, enable_guess=True): p = lib.ndpi_detection_giveup(self._detection_module, - flow._C, + flow.C, enable_guess, ffi.new("uint8_t*", 0)) return ndpi_protocol(C=p, @@ -82,20 +82,20 @@ class NDPI(object): class NDPIFlow(object): - __slots__ = ("_C") + __slots__ = "C" @property def confidence(self): - confidence = self._C.confidence + confidence = self.C.confidence return ndpi_confidence(id=confidence, name=ffi.string(lib.ndpi_confidence_get_name(confidence)).decode('utf-8', errors='ignore')) def __init__(self): - self._C = lib.ndpi_py_initialize_flow() + self.C = lib.ndpi_py_initialize_flow() def __del__(self): - if self._C != ffi.NULL: - lib.ndpi_flow_free(self._C) - self._C = ffi.NULL + if self.C != ffi.NULL: + lib.ndpi_flow_free(self.C) + self.C = ffi.NULL |