Hi there,
First, let me preface this by saying that our module API is still undergoing changes, so anything that I post here may be changed in the future.
From what I understand, you are asking about implementing your own request handler based on the URL given.
So for example, example.com/index.bar would be handled by a ".bar" handler?
Before I go into an example, you asked about reregistering the handlers each request.
The module I used as an example does this, and basically this allows you to do more involved checks for if you want your module to handle the request(i.e. check the query string, cookies, request body, etc.).
If you want the module to be statically assigned to a specific suffix, after creating and registering the module, on the Web Admin, go to Script Handler and create a new one.
Here, you can specify the suffix to handle and how you want it to be handled (in this case, module handler and your module name).
If that is the case, I suggest taking a look at addon/example/testparam.c
Important things to note:
- MNAME must be the same as the file name.
- The lsi_serverhook_t array contains all the functions that you wish to "hook" onto a request, at a given hook point.
- IMPORTANT: This should always end with lsi_serverhook_t_END
- The lsi_handler_t object should contain the handler's main, on read, on write, and on clean up functions. The last three are optional, but the main function is what starts your handler.
- NOTE: There can only be one handler per module.
- The (optional) lsi_config_t object is for if you have any configurations you wish to set up for the module on server start up.
- This should contain the parsing function, the freeing function, and any parameters you wish to pass to the parser.
- Finally, the lsi_module_t object is what pulls everything together.
- This should always have LSI_MODULE_SIGNATURE, followed by:
- an Initializer function - if you need to do any initialization on server start up, this is the place to do it.
- The handler object - This is optional if you don't have a handler
- The configuration parser object - This is also optional if you don't have any configurations.
- Version string.
- The server hooks object - The functions that you want to hook onto a request.
With that, I will get into more detail about the functions in this particular module:
reg_handler - This hooks into the URI_MAP hook point. Essentially, what we do in this function is check the uri that was passed in, and if it contains what we want to handle, register the request handler.
If you wish to statically handle a specific suffix, this function is not necessary.
testparam_handlerBeginProcess - This is your handler's "main" function. It will only be called if you registered it in the previous function.
You can set the response headers and append to the response body here (it can be incrementally or all at once), then once you are done, you end the response.
Final notes:
- You are required to include <ls.h>, else nothing will work.
- We have runtime libraries in include/lsr/ that you may find useful.
We tried to document the functions available as much as we could, but if something is unclear, please let us know!
If you have any more questions, let us know and we'll see what we can do to help.
Kevin