# Module API

## Functions

### `int xbind(xl_api_t *xl_api)`

Bind to the xprint module API.

Meaning of the parameters is as follows:

- xl_api - structure that the xprint module functions are bind to. The functions can be executed as xl_api.xparse(), xl_api.xprint()...

Return value: 0 - success, <0 - error.

### `int xparse(char *s, xl_elog_p *el)`

Parse an xl-formatted string in private memory.

Meaning of the parameters is as follows:

- s - string to be parsed.

- el - returned xl-lib list.

Return value: 0 - success, <0 - error.

### `int shm_xparse(char *s, xl_elog_p *el)`

Parse an xl-formatted string in shared memory. See xparse() function for details.

### `int xparse2(char *s, xl_elog_p *el, xl_parse_cb cb)`

Parse an xl-formatted string in private memory. This function is able to identify regular expression back references, for example \1, \2, \3... When a back reference is found the callback function is called that is supposed to farther parse the back reference and fill in the xl_elog structure.

Meaning of the parameters is as follows:

- s - string to be parsed.

- el - returned xl-lib list.

- cb - callback function for parsing the regular expression back references.

The prototype of the callback function is: typedef int (*xl_parse_cb) (str *s, int shm, xl_elog_p el);

Parameters of the callback function:

- s - regular expression back reference to be parsed (without the leading '\' character).

- shm - indicates whether or not shared memory needs to be used. (1: shared memory, 0: private memory)

- el - pointer to the xl-lib list item that is supposed to be filled in.

Return value: 0 - success, <0 - error.

### `int shm_xparse2(char *s, xl_elog_p *el, xl_parse_cb cb)`

Parse an xl-formatted string in shared memory supporting regular expression back references. See xparse2() function for details.

### `xfree(xl_elog_p el)`

Free the xl-lib list allocated by xparse() or xparse2().

Meaning of the parameters is as follows:

- el - xl-lib list to be freed.

### `shm_xfree(xl_elog_p el)`

Free the xl-lib list allocated by shm_xparse() or shm_xparse2().

Meaning of the parameters is as follows:

- el - xl-lib list to be freed.

### `int xprint(struct sip_msg* msg, xl_elog_p el, char *buf, int *len)`

Evaluate the xl-formatted string and print the result into a buffer.

Meaning of the parameters is as follows:

- msg - SIP message pointer.

- el - xl-lib list to be evaluated.

- buf - pre-allocated buffer that is filled in with the result.

- len - length of the printed string. len needs to be set to the maximum length of the result buffer before calling this function.

Return value: 0 - success, <0 - error.

### `str *xnulstr()`

Return the string "<null>".