comparison libfreeDiameter/dispatch.c @ 639:95a784729cac

Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 20 Dec 2010 13:07:06 +0900
parents e93428e7ab31
children ae29bf971f20
comparison
equal deleted inserted replaced
638:9448cba86673 639:95a784729cac
53 int eyec; /* Eye catcher, DISP_EYEC */ 53 int eyec; /* Eye catcher, DISP_EYEC */
54 struct fd_list all; /* link in the all_handlers list */ 54 struct fd_list all; /* link in the all_handlers list */
55 struct fd_list parent;/* link in dictionary cb_list or in any_handlers */ 55 struct fd_list parent;/* link in dictionary cb_list or in any_handlers */
56 enum disp_how how; /* Copy of registration parameter */ 56 enum disp_how how; /* Copy of registration parameter */
57 struct disp_when when; /* Copy of registration parameter */ 57 struct disp_when when; /* Copy of registration parameter */
58 int (*cb)( struct msg **, struct avp *, struct session *, enum disp_action *); /* The callback itself */ 58 int (*cb)( struct msg **, struct avp *, struct session *, void *, enum disp_action *); /* The callback itself */
59 void *opaque; /* opaque data passed back to the callback */
59 }; 60 };
60 61
61 #define DISP_EYEC 0xD15241C1 62 #define DISP_EYEC 0xD15241C1
62 #define VALIDATE_HDL( _hdl ) \ 63 #define VALIDATE_HDL( _hdl ) \
63 ( ( ( _hdl ) != NULL ) && ( ((struct disp_hdl *)( _hdl ))->eyec == DISP_EYEC ) ) 64 ( ( ( _hdl ) != NULL ) && ( ((struct disp_hdl *)( _hdl ))->eyec == DISP_EYEC ) )
90 continue; 91 continue;
91 if (hdl->when.value && (hdl->when.value != obj_enu)) 92 if (hdl->when.value && (hdl->when.value != obj_enu))
92 continue; 93 continue;
93 94
94 /* We have a match, the cb must be called. */ 95 /* We have a match, the cb must be called. */
95 CHECK_FCT( (*hdl->cb)(msg, avp, sess, action) ); 96 CHECK_FCT( (*hdl->cb)(msg, avp, sess, hdl->opaque, action) );
96 97
97 if (*action != DISP_ACT_CONT) 98 if (*action != DISP_ACT_CONT)
98 break; 99 break;
99 100
100 if ( *msg == NULL ) 101 if ( *msg == NULL )
106 } 107 }
107 108
108 /**************************************************************************************/ 109 /**************************************************************************************/
109 110
110 /* Create a new handler and link it */ 111 /* Create a new handler and link it */
111 int fd_disp_register ( int (*cb)( struct msg **, struct avp *, struct session *, enum disp_action *), 112 int fd_disp_register ( int (*cb)( struct msg **, struct avp *, struct session *, void *, enum disp_action *),
112 enum disp_how how, struct disp_when * when, struct disp_hdl ** handle ) 113 enum disp_how how, struct disp_when * when, void * opaque, struct disp_hdl ** handle )
113 { 114 {
114 struct fd_list * cb_list = NULL; 115 struct fd_list * cb_list = NULL;
115 struct disp_hdl * new; 116 struct disp_hdl * new;
116 struct dict_object * type_enum, * type_avp; 117 struct dict_object * type_enum, * type_avp;
117 struct dictionary * dict = NULL; 118 struct dictionary * dict = NULL;
168 new->when.command = when->command; 169 new->when.command = when->command;
169 case DISP_HOW_APPID: 170 case DISP_HOW_APPID:
170 new->when.app = when->app; 171 new->when.app = when->app;
171 } 172 }
172 new->cb = cb; 173 new->cb = cb;
174 new->opaque = opaque;
173 175
174 /* Now, link this new element in the appropriate lists */ 176 /* Now, link this new element in the appropriate lists */
175 CHECK_POSIX( pthread_rwlock_wrlock(&fd_disp_lock) ); 177 CHECK_POSIX( pthread_rwlock_wrlock(&fd_disp_lock) );
176 fd_list_insert_before(&all_handlers, &new->all); 178 fd_list_insert_before(&all_handlers, &new->all);
177 fd_list_insert_before(cb_list, &new->parent); 179 fd_list_insert_before(cb_list, &new->parent);
183 185
184 return 0; 186 return 0;
185 } 187 }
186 188
187 /* Delete a handler */ 189 /* Delete a handler */
188 int fd_disp_unregister ( struct disp_hdl ** handle ) 190 int fd_disp_unregister ( struct disp_hdl ** handle, void ** opaque )
189 { 191 {
190 struct disp_hdl * del; 192 struct disp_hdl * del;
191 TRACE_ENTRY("%p", handle); 193 TRACE_ENTRY("%p", handle);
192 CHECK_PARAMS( handle && VALIDATE_HDL(*handle) ); 194 CHECK_PARAMS( handle && VALIDATE_HDL(*handle) );
193 del = *handle; 195 del = *handle;
196 CHECK_POSIX( pthread_rwlock_wrlock(&fd_disp_lock) ); 198 CHECK_POSIX( pthread_rwlock_wrlock(&fd_disp_lock) );
197 fd_list_unlink(&del->all); 199 fd_list_unlink(&del->all);
198 fd_list_unlink(&del->parent); 200 fd_list_unlink(&del->parent);
199 CHECK_POSIX( pthread_rwlock_unlock(&fd_disp_lock) ); 201 CHECK_POSIX( pthread_rwlock_unlock(&fd_disp_lock) );
200 202
203 if (opaque)
204 *opaque = del->opaque;
205
201 free(del); 206 free(del);
202 return 0; 207 return 0;
203 } 208 }
204 209
205 /* Delete all handlers */ 210 /* Delete all handlers */
206 void fd_disp_unregister_all ( void ) 211 void fd_disp_unregister_all ( void )
207 { 212 {
208 TRACE_ENTRY(""); 213 TRACE_ENTRY("");
209 while (!FD_IS_LIST_EMPTY(&all_handlers)) { 214 while (!FD_IS_LIST_EMPTY(&all_handlers)) {
210 CHECK_FCT_DO( fd_disp_unregister((void *)&(all_handlers.next->o)), /* continue */ ); 215 CHECK_FCT_DO( fd_disp_unregister((void *)&(all_handlers.next->o), NULL), /* continue */ );
211 } 216 }
212 return; 217 return;
213 } 218 }
"Welcome to our mercurial repository"