diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2024-08-08 14:34:10 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2024-08-08 14:34:10 -0300 |
| commit | 56f96f0bdc6187ce19064d311c000656ae68008b (patch) | |
| tree | 104a7843861befbd4da34a66f03b85d7b9ea0df9 /libfdcore/hooks.c | |
| parent | 3e8d3ed13f58af810934de696c34bf5bf16ddcc6 (diff) | |
New upstream version 1.5.0upstream
Diffstat (limited to 'libfdcore/hooks.c')
| -rw-r--r-- | libfdcore/hooks.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/libfdcore/hooks.c b/libfdcore/hooks.c index f035614..b812649 100644 --- a/libfdcore/hooks.c +++ b/libfdcore/hooks.c @@ -2,7 +2,7 @@ * Software License Agreement (BSD License) * * Author: Sebastien Decugis <sdecugis@freediameter.net> * * * -* Copyright (c) 2015, WIDE Project and NICT * +* Copyright (c) 2020, WIDE Project and NICT * * All rights reserved. * * * * Redistribution and use of this software in source and binary forms, with or without modification, are * @@ -195,7 +195,7 @@ void fd_hook_associate(struct msg * msg, struct fd_msg_pmdl * pmdl) } /* 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 @@ static struct fd_hook_permsgdata * get_or_create_pmd(struct fd_msg_pmdl *pmdl, s /* 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 @@ static struct fd_hook_permsgdata * get_or_create_pmd(struct fd_msg_pmdl *pmdl, s 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 @@ void fd_hook_call(enum fd_hook_type type, struct msg * msg, struct fd_peer * p /* 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 */ @@ -327,7 +332,9 @@ void fd_hook_call(enum fd_hook_type type, struct msg * msg, struct fd_peer * p /* There was no registered handler, default behavior for this hook */ switch (type) { case HOOK_DATA_RECEIVED: { +#ifdef DEBUG struct fd_cnx_rcvdata *rcv_data = other; +#endif LOG_A("RCV: %zd bytes", rcv_data->length); break; } |
