Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with porting modsecurity library #451

Closed
artemMartynenko opened this issue Jan 19, 2021 · 14 comments
Closed

Help with porting modsecurity library #451

artemMartynenko opened this issue Jan 19, 2021 · 14 comments
Labels

Comments

@artemMartynenko
Copy link

I'm trying to create a new preset for modsecurity lib. I`m already done with adding Info for Parser to properly wrap the library and generate Java Pointers without any Java compilation errors. Now I have an issue with generating and compiling C++ jni wrappers based on Java classes, it produces a lot of C++ compilation errors. A lot of errors in incorrect syntax and variables and I cannot recognize a starting point for fixing in the cause of errors are in generated code. It will be greater if you can help me with troubleshooting. Here is my fork with added modsecurity preset. You can run it and see all errors with command mvn clean install --projects .,modsecurity as described in wiki.

@saudet
Copy link
Member

saudet commented Jan 20, 2021

Please read the following and let me know if you have any questions about that or about errors that don't seem to be related to any of it. Thanks!
https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes

@artemMartynenko
Copy link
Author

I went again through that link. Currently, I can`t find the reasons for the errors. I found from previous issues that I miss to define {"UNIQUE_PTR_NAMESPACE std", "SHARED_PTR_NAMESPACE std"}. It fixed some errors but add a new portion.
It will be greater if you can help me with the identification. Currently, I see few types of errors.

  1. error: cannot apply ‘offsetof’ to member function.
  2. cannot convert ‘std::__cxx11::basic_string’ to ‘std::string*’ {aka ‘std::__cxx11::basic_string*’}
  3. invalid conversion from ‘signed char*’ to ‘const char*’ [-fpermissive]
  4. no match for ‘operator=’ (operand types are ‘std::shared_ptr<std::__cxx11::basic_string >’ and ‘std::__cxx11::basic_string’)
  5. no matching function for call to ‘SharedPtrAdapter::SharedPtrAdapter(std::shared_ptr<std::__cxx11::basic_string >&)’
  6. invalid user-defined conversion from ‘SharedPtrAdapter’ to ‘signed char*’ [-fpermissive]
  7. ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]

There are a lot of errors but they are similar, just use another type.

Can you suggest the reasons and provide some examples of how it can be fixed?

Thanks!

@saudet
Copy link
Member

saudet commented Jan 22, 2021

Please provide the whole log of errors returned by your C++ compiler, as well as the wrapper classes generated by JavaCPP. Thanks!

@artemMartynenko
Copy link
Author

artemMartynenko commented Jan 22, 2021

Yep, Thanks.
Here are log file and generated files.
gen.zip
output.log

@saudet
Copy link
Member

saudet commented Jan 23, 2021

There's a lot of classes in there. Start by reducing that to a small number of core classes, and once those work, we can move forward with more classes, and repeat until everything is done.

Since the library has a C API though, I would recommend starting with that API, first. It should be pretty easy to get that one working. And then if you feel that there's something missing from that API, we can start again to look at mapping the C++ API.

@artemMartynenko
Copy link
Author

artemMartynenko commented Jan 26, 2021

Thank you for your advice. I tried to reduce the number of classes and header files leaving only the most needed for library usage. Now I have a compilable version, but to achieve that I skipped some fields and methods and some of them shouldn`t be skipped for future library usage.
The main error that I have is about usage of std::shared_ptr<std::string> and ```std::unique_ptrstd::string```. If fields with those types are not skipped everything ok with parsing process and java classes compilation but jni compilation fails with such errors:

  1. error: no matching function for call to UniquePtrAdapter<char>::UniquePtrAdapter(std::unique_ptr<std::__cxx11::basic_string<char> >)
  2. invalid cast from type ‘SharedPtrAdapter<char>’ to type ‘std::string*’ {aka ‘std::__cxx11::basic_string<char>*’}
  3. no matching function for call to ‘SharedPtrAdapter<char>::SharedPtrAdapter(std::shared_ptr<std::__cxx11::basic_string<char> >&)’
    I think it can be easily fixed and I will be very grateful for your help.
    Thanks!

@artemMartynenko
Copy link
Author

And one more question. How can I deploy an artifact to use in the example project and test if everything works fine?
Thanks!

@saudet
Copy link
Member

saudet commented Jan 26, 2021

Supporting something like std::shared_ptr<std::string> or std::unique_ptr<std::string> is pretty tricky because usually both types are mapped with adapters, and JavaCPP doesn't currently support chaining those. The easiest thing to do is probably to create a wrapper class for std::string like this one:
https://github.com/bytedeco/javacpp-presets/blob/master/tensorflow/src/main/java/org/bytedeco/tensorflow/StringArray.java

And one more question. How can I deploy an artifact to use in the example project and test if everything works fine?
Thanks!

Just running mvn install will deploy everything locally, and you can test everything that way.

@artemMartynenko
Copy link
Author

Hello. Thank you for your help. With your advice, I have fixed most of the problems and the java wrapper for modsecurity is almost ready. But currently, I faced a build problem. I'm trying to use this preset as dependent lib in the Spring Boot application. Spring Boot builds uber jar and when I`m trying to run this application in docker or on another workspace I got this error.
/root/.javacpp/cache/modsecurity-1.5.5-SNAPSHOT-linux-x86_64.jar/org/bytedeco/modsecurity/linux-x86_64/libjniglobal.so: libmodsecurity.so.3: cannot open shared object file: No such file or directory
What could be the reason?
Thanks!

@saudet
Copy link
Member

saudet commented Feb 12, 2021

It probably just means the library file isn't there? Are you sure it's in the uber JAR?

@artemMartynenko
Copy link
Author

It was another fault. The libraries were inside JAR, but the error was irrelevant because dependent libraries for ModSecurity were not installed inside docker. Now everything works fine. Thank you for your help!

@artemMartynenko
Copy link
Author

Can I create a pull request for javacpp-presets with added ModSecurity?

@saudet
Copy link
Member

saudet commented Feb 14, 2021

Yes, by all means, please do! Thanks

@artemMartynenko
Copy link
Author

Hello! Sorry for the delay with PR. here is it #1012. I think you can close the issue and we can continue in PR if there will need some changes. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants