diff options
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rw-r--r-- | examples/c-simple/c-simple.c | 10 | ||||
-rwxr-xr-x | examples/py-machine-learning/sklearn-random-forest.py | 17 |
3 files changed, 24 insertions, 4 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 70327a995..4f4429ef9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,6 +65,7 @@ build_and_test_static_libndpi: - > if ldd ./build-cmake-submodule/nDPId | grep -qoEi libndpi; then \ echo 'nDPId linked against a static libnDPI should not contain a shared linked libnDPI.' >&2; false; fi + - cc nDPId.c utils.c -I./build-cmake-submodule/libnDPI/include/ndpi -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include -o /tmp/a.out -lpcap ./build-cmake-submodule/libnDPI/lib/libndpi.a -pthread -lm -lz artifacts: expire_in: 1 week paths: diff --git a/examples/c-simple/c-simple.c b/examples/c-simple/c-simple.c index a923d1424..642611f07 100644 --- a/examples/c-simple/c-simple.c +++ b/examples/c-simple/c-simple.c @@ -253,14 +253,20 @@ int main(int argc, char ** argv) enum nDPIsrvd_parse_return parse_ret = nDPIsrvd_parse_all(sock); if (parse_ret != PARSE_NEED_MORE_DATA) { - printf("Could not parse json string: %s\n", nDPIsrvd_enum_to_string(parse_ret)); + printf("Could not parse json string %s: %.*s\n", + nDPIsrvd_enum_to_string(parse_ret), + nDPIsrvd_json_buffer_length(sock), + nDPIsrvd_json_buffer_string(sock)); break; } } if (main_thread_shutdown == 0 && read_ret != READ_OK) { - printf("Parse read %s\n", nDPIsrvd_enum_to_string(read_ret)); + printf("Parse read %s at JSON: %.*s\n", + nDPIsrvd_enum_to_string(read_ret), + nDPIsrvd_json_buffer_length(sock), + nDPIsrvd_json_buffer_string(sock)); } return 1; diff --git a/examples/py-machine-learning/sklearn-random-forest.py b/examples/py-machine-learning/sklearn-random-forest.py index 9103bb427..275376ba2 100755 --- a/examples/py-machine-learning/sklearn-random-forest.py +++ b/examples/py-machine-learning/sklearn-random-forest.py @@ -168,6 +168,9 @@ def onJsonLineRecvd(json_dict, instance, current_flow, global_user_data): return True def isProtoClass(proto_class, line): + if type(proto_class) != list or type(line) != str: + raise TypeError('Invalid type: {}/{}.'.format(type(proto_class), type(line))) + s = line.lower() for x in range(len(proto_class)): @@ -278,9 +281,19 @@ if __name__ == '__main__': for line in reader: try: X += getRelevantFeaturesCSV(line) - y += [isProtoClass(args.proto_class, line['proto'])] except RuntimeError as err: - print('Error: `{}\'\non line {}: {}'.format(err, reader.line_num - 1, line)) + print('Runtime Error: `{}\'\non line {}: {}'.format(err, reader.line_num - 1, line)) + continue + except TypeError as err: + print('Type Error: `{}\'\non line {}: {}'.format(err, reader.line_num - 1, line)) + continue + + try: + y += [isProtoClass(args.proto_class, line['proto'])] + except TypeError as err: + X.pop() + print('Type Error: `{}\'\non line {}: {}'.format(err, reader.line_num - 1, line)) + continue sys.stderr.write('CSV data set contains {} entries.\n'.format(len(X))) |