Mercurial > hg > freeDiameter
changeset 1329:175f2eb883a0
Add function to retrieve pmd structure associated with a request.
Returns NULL in case of error.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Mon, 27 Nov 2017 15:27:31 +0100 |
parents | 81af4f5a517a |
children | e7726fae1e7f |
files | include/freeDiameter/libfdcore.h libfdcore/hooks.c |
diffstat | 2 files changed, 18 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/include/freeDiameter/libfdcore.h Mon Nov 27 15:22:42 2017 +0100 +++ b/include/freeDiameter/libfdcore.h Mon Nov 27 15:27:31 2017 +0100 @@ -1154,6 +1154,10 @@ /* Use the following function to retrieve any pmd structure associated with a request matching the current answer. Returns NULL in case of error / no such structure */ struct fd_hook_permsgdata * fd_hook_get_request_pmd(struct fd_hook_data_hdl *data_hdl, struct msg * answer); +/* Use the following function to retrieve any pmd structure associated with a request. Returns NULL in case of error */ +struct fd_hook_permsgdata * fd_hook_get_pmd(struct fd_hook_data_hdl *data_hdl, struct msg * msg); + + /* The following is used by HOOK_MASK macro */ uint32_t fd_hook_mask_helper(int dummy, ...);
--- a/libfdcore/hooks.c Mon Nov 27 15:22:42 2017 +0100 +++ b/libfdcore/hooks.c Mon Nov 27 15:27:31 2017 +0100 @@ -195,7 +195,7 @@ } /* Return the location of the permsgdata area corresponding to this handle, after eventually having created it. Return NULL in case of failure */ -static struct fd_hook_permsgdata * get_or_create_pmd(struct fd_msg_pmdl *pmdl, struct fd_hook_hdl * h) +static struct fd_hook_permsgdata * get_or_create_pmd(struct fd_msg_pmdl *pmdl, struct fd_hook_data_hdl * h) { struct fd_hook_permsgdata * ret = NULL; struct fd_list * li; @@ -209,22 +209,22 @@ /* Search in the list for an item with the same handle. The list is ordered by this handle */ for (li=pmdl->sentinel.next; li != &pmdl->sentinel; li = li->next) { struct pmd_list_item * pli = (struct pmd_list_item *) li; - if (pli->hdl == h->data_hdl) + if (pli->hdl == h) ret = &pli->pmd; - if (pli->hdl >= h->data_hdl) + if (pli->hdl >= h) break; } if (!ret) { /* we need to create a new one and insert before li */ struct pmd_list_item * pli; - CHECK_MALLOC_DO( pli = malloc(sizeof_pmd(h->data_hdl)), ); + CHECK_MALLOC_DO( pli = malloc(sizeof_pmd(h)), ); if (pli) { - memset(pli, 0, sizeof_pmd(h->data_hdl)); + memset(pli, 0, sizeof_pmd(h)); fd_list_init(&pli->chain, pli); - pli->hdl = h->data_hdl; + pli->hdl = h; ret = &pli->pmd; - if (h->data_hdl->pmd_init_cb) { - (*h->data_hdl->pmd_init_cb)(ret); + if (h->pmd_init_cb) { + (*h->pmd_init_cb)(ret); } fd_list_insert_before(li, &pli->chain); } @@ -234,6 +234,11 @@ return ret; } +struct fd_hook_permsgdata * fd_hook_get_pmd(struct fd_hook_data_hdl *data_hdl, struct msg * msg) +{ + return get_or_create_pmd(fd_msg_pmdl_get(msg), data_hdl); +} + struct fd_hook_permsgdata * fd_hook_get_request_pmd(struct fd_hook_data_hdl *data_hdl, struct msg * answer) { struct msg * qry; @@ -306,7 +311,7 @@ /* do we need to handle pmd ? */ if (h->data_hdl && pmdl) { - pmd = get_or_create_pmd(pmdl, h); + pmd = get_or_create_pmd(pmdl, h->data_hdl); } /* Now, call this callback */