Navigation


Changeset 1101:40b48a3997a2 in freeDiameter


Ignore:
Timestamp:
May 9, 2013, 1:06:03 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Parents:
1098:f38d77f9cfd3 (diff), 1100:4b7192d0ffde (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merged

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/libfdcore.h

    r1098 r1101  
    950950       
    951951        HOOK_MESSAGE_FAILOVER,
    952                 /* Hook called when a message that was sent to a peer is being requeued, because e.g. the connection was teared down.
     952                /* Hook called when a message that was sent to a peer is being requeued, because e.g. the connection was torn down.
    953953                   In that case the message will go again through the routing process.
    954954                 - {msg} points to the corresponding request message (the answer is discarded). Again, the objects may not have been dictionary resolved. If you
     
    10191019
    10201020
    1021 /* Type if the {permsgdata}. It is up to each extension to define its own structure. This is opaque for the framework. */
     1021/* Type of the {permsgdata} pointer. It is up to each extension to define its own structure. This is opaque for the framework. */
    10221022struct fd_hook_permsgdata;
    10231023
  • include/freeDiameter/libfdcore.h

    r1099 r1101  
    879879/* These functions allow an extension to collect state information about the
    880880 * framework, as well as being hooked at some key checkpoints in the processing
    881  * for logging / statistics purpose.
     881 * for logging or statistics purpose.
    882882 */
    883883 
     
    887887 * PARAMETERS:
    888888 *  type        : The type of hook that triggered this call, in case same cb is registered for several hooks.
    889  *  msg         : If relevant, the pointer to the message trigging the call. NULL otherwise.
     889 *  msg         : If relevant, the pointer to the message triggering the call. NULL otherwise.
    890890 *  peer        : If relevant, the pointer to the peer associated with the call. NULL otherwise.
    891891 *  other       : For some callbacks, the remaining information is passed in this parameter. See each hook detail.
    892892 *  permsgdata  : Structure associated with a given message, across several hooks.
    893  *                 Same structure is associated with requests and corresponding answers.
     893 *                 A different structure is associated with requests and corresponding answers.
    894894 *                 See fd_hook_data_hdl below for details.
    895895 *                 If no fd_hook_data_hdl is registered with this callback, this parameter is always NULL
     
    916916                 - {msg} is NULL.
    917917                 - {peer} is NULL.
    918                  - {*other} is NULL, {other} points to a valid location where you can store a pointer.
    919                     This same pointer will then passed to the next hook, once message is processed.
    920                     IMPORTANT: free() will be called on this pointer if any problem, so this pointer must be malloc'd.
    921                  - {permsgdata} is NULL.
     918                 - {other} is a pointer to a structure { size_t len; uint8_t * buf; } containing the received buffer.
     919                 - {permsgdata} points to either a new empty structure allocated for this message (cf. fd_hook_data_hdl), or NULL if no hdl is registered.
    922920                 */
    923921                 
     
    928926                 - {peer} is set if the message is received from a peer's connection, and NULL if the message is from a new client
    929927                   connected and not yet identified
    930                  - {*other} contains the pointer stored with the HOOK_DATA_RECEIVED hook if any, NULL otherwise. After this hook returns, free(*other) is called if not NULL.
    931                  - {permsgdata} points to either a new empty structure allocated for this request (cf. fd_hook_data_hdl), or the request's existing structure if the message is an answer.
     928                 - {other} is NULL.
     929                 - {permsgdata} points to either a new empty structure allocated for this message or the one passed to HOOK_DATA_RECEIVED if used.
    932930                 */
    933931       
     
    946944                   try to call fd_msg_parse_dict, it will slow down the operation of a relay agent.
    947945                 - {peer} is set if the message is sent to a peer's connection, and NULL if the message is sent to a new client
    948                    connected and not yet identified / being rejected
     946                   connected and not yet identified, or being rejected
    949947                 - {other} is NULL.
    950948                 - {permsgdata} points to existing structure if any, or a new structure otherwise.
    951                     If the message is an answer, the structure is shared with the corresponding request.
    952949                 */
    953950       
     
    959956                 - {peer} is the peer this message was previously sent to.
    960957                 - {other} is NULL.
    961                  - {permsgdata} points to existing structure associated with this request.
     958                 - {permsgdata} points to existing structure if any, or a new structure otherwise.
    962959                 */
    963960       
     
    994991       
    995992        HOOK_MESSAGE_DROPPED,
    996                 /* Hook called when a message is being discarded by the framework because of some error.
    997                    It is probably a good idea to log this for analysis.
     993                /* Hook called when a message is being discarded by the framework because of some error condition (normal or abnormal).
     994                   It is probably a good idea to log this for analysis / backup.
    998995                 - {msg} points to the message, which will be freed as soon as the hook returns.
    999996                 - {peer} is NULL.
     
    10351032 *
    10361033 * PARAMETERS:
    1037  *  permsgdata_new_cb     : function called to initialize a new empty fd_hook_permsgdata structure, when a hook will be called for a message with no structure yet. If the function returns NULL, it will be called again for the next hook.
    1038  *  permsgdata_destroy_cb : function called when a message is being disposed. It should free the resources associated with the fd_hook_permsgdata.
    1039  *  new_handle            : On success, a handler to the registered callback is stored here.
     1034 *  permsgdata_size     : the size of the fd_hook_permsgdata structure.
     1035 *  permsgdata_init_cb  : function called to initialize a new fd_hook_permsgdata structure, when a hook will be called for a message that does not have such structure yet.
     1036 *                           The memory is already allocated and blanked, so you can pass NULL if no further handling is required.
     1037 *  permsgdata_fini_cb  : function called when a message is being disposed. It should free the resources associated with the fd_hook_permsgdata.
     1038 *                           You can pass NULL if no special handling is required. The memory of the permsgdata structure itself will be freed by the framework.
     1039 *  new_handle          : On success, a handler to the registered callback is stored here.
    10401040 *                           This handler will be used to unregister the cb.
    10411041 *
    10421042 * DESCRIPTION:
    10431043 *   Register a new fd_hook_data_hdl. This handle is used during hooks registration (see below) in order to associate data with the messages, to allow keeping tracking of the message easily.
    1044  *  Note that these handlers are statically allocated and cannot be unregistered.
     1044 *  Note that these handlers are statically allocated and cannot be unregistered. FD_HOOK_HANDLE_LIMIT handlers can be registered at maximum (recompile libfdproto if you change this value)
    10451045 *
    10461046 * RETURN VALUE:
     
    10501050 */
    10511051int fd_hook_data_register(
    1052         struct fd_hook_permsgdata * (*permsgdata_new_cb)     (void),
    1053         void (*permsgdata_destroy_cb) (struct fd_hook_permsgdata *),
    1054         struct fd_hook_data_hdl **    new_handle
     1052        size_t permsgdata_size,
     1053        void (*permsgdata_init_cb) (struct fd_hook_permsgdata *),
     1054        void (*permsgdata_fini_cb) (struct fd_hook_permsgdata *),
     1055        struct fd_hook_data_hdl **new_handle
    10551056);
    1056 
    10571057
    10581058/* A handler associated with a registered hook callback (for cleanup) */
     
    10631063 *
    10641064 * PARAMETERS:
    1065  *  type          : The fd_hook_type for which this cb is registered. Call several times if you want to register for several hooks.
     1065 *  type_mask     : A bitmask of fd_hook_type bits for which this cb is registered, e.g. ((1 << HOOK_MESSAGE_RECEIVED) || (1 << HOOK_MESSAGE_SENT))
    10661066 *  fd_hook_cb    : The callback function to register (see prototype above).
    10671067 *  regdata       : Pointer to pass to the callback when it is called. The data is opaque to the daemon.
     
    10791079 *  ENOMEM      : Not enough memory to complete the operation
    10801080 */
    1081 int fd_hook_register (  enum fd_hook_type type,
    1082                         void (*fd_hook_cb)(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, void * regdata),
    1083                         void * regdata,
     1081int fd_hook_register (  uint32_t type_mask,
     1082                        void (*fd_hook_cb)(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata),
     1083                        void  *regdata,
    10841084                        struct fd_hook_data_hdl *data_hdl,
    10851085                        struct fd_hook_hdl ** handler );
  • include/freeDiameter/libfdproto.h

    r1098 r1101  
    8080#include <stdarg.h>
    8181
    82 #ifdef DEBUG
    83 #include <libgen.h>     /* for basename if --dbg_file is specified */
    84 #endif /* DEBUG */
     82#include <libgen.h>     /* for basename */
    8583
    8684#ifdef SWIG
  • include/freeDiameter/libfdproto.h

    r1100 r1101  
    25482548
    25492549
     2550/* Helper for the hooks mechanism, for use from libfdcore */
     2551struct fd_msg_pmdl {
     2552        struct fd_list sentinel; /* if the sentinel.o field is NULL, the structure is not initialized. Otherwise it points to the cleanup function in libfdcore. */
     2553        pthread_mutex_t lock;
     2554};
     2555#define FD_MSG_PMDL_INITIALIZER(pmdl_ptr)        { FD_LIST_INITIALIZER(  (pmdl_ptr)->sentinel       ), PTHREAD_MUTEX_INITIALIZER }
     2556struct fd_msg_pmdl * fd_msg_pmdl_get(struct msg * msg);
     2557
    25502558/***************************************/
    25512559/*   Manage AVP values                 */
  • libfdcore/cnxctx.c

    r1098 r1101  
    17581758       
    17591759                default:
    1760                         TRACE_DEBUG(INFO, "Unknwon protocol: %d", conn->cc_proto);
     1760                        TRACE_DEBUG(INFO, "Unknown protocol: %d", conn->cc_proto);
    17611761                        ASSERT(0);
    17621762                        return ENOTSUP; /* or EINVAL... */
  • libfdcore/cnxctx.c

    r1099 r1101  
    736736                }
    737737               
     738                // fd_msg_log(....)
     739               
    738740                /* We have received a complete message, pass it to the daemon */
    739741                CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), /* continue or destroy everything? */);
  • libfdproto/messages.c

    r1098 r1101  
    12551255                return anscb ? EINVAL : 0; /* we associate with requests only */
    12561256       
    1257         CHECK_PARAMS( (anscb == NULL)    || (msg->msg_cb.anscb == NULL) ); /* We are not overwritting a cb */
    1258         CHECK_PARAMS( (expirecb == NULL) || (msg->msg_cb.expirecb == NULL) ); /* We are not overwritting a cb */
     1257        CHECK_PARAMS( (anscb == NULL)    || (msg->msg_cb.anscb == NULL) ); /* We are not overwriting a cb */
     1258        CHECK_PARAMS( (expirecb == NULL) || (msg->msg_cb.expirecb == NULL) ); /* We are not overwriting a cb */
    12591259       
    12601260        /* Associate callback and data with the message, if any */
  • libfdproto/messages.c

    r1099 r1101  
    137137        DiamId_t                 msg_src_id;            /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
    138138        size_t                   msg_src_id_len;        /* cached length of this string */
    139        
     139        struct fd_msg_pmdl       msg_pmdl;              /* list of permessagedata structures. */
    140140};
    141141
     
    674674        }
    675675       
     676        if ((obj->type == MSG_MSG) && (_M(obj)->msg_pmdl.sentinel.o != NULL)) {
     677                ((void (*)(struct fd_msg_pmdl *))_M(obj)->msg_pmdl.sentinel.o)(&_M(obj)->msg_pmdl);
     678        }
     679       
    676680        /* free the object */
    677681        free(obj);
     
    14961500       
    14971501        return 0;
     1502}
     1503
     1504/* Retrieve the location of the pmd list for the message; return NULL if failed */
     1505struct fd_msg_pmdl * fd_msg_pmdl_get(struct msg * msg)
     1506{
     1507        CHECK_PARAMS_DO( CHECK_MSG(msg), return NULL );
     1508        return &msg->msg_pmdl;
    14981509}
    14991510
Note: See TracChangeset for help on using the changeset viewer.