comparison include/freeDiameter/libfreeDiameter.h @ 8:3e143f047f78

Backup for the week-end
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 18 Sep 2009 18:54:07 +0900
parents e5af94b04946
children c5c99c73c2bf
comparison
equal deleted inserted replaced
7:e5af94b04946 8:3e143f047f78
34 *********************************************************************************************************/ 34 *********************************************************************************************************/
35 35
36 /* This file contains the definitions of functions and types used by the libfreeDiameter library. 36 /* This file contains the definitions of functions and types used by the libfreeDiameter library.
37 * 37 *
38 * This library is meant to be used by both the freeDiameter daemon and its extensions. 38 * This library is meant to be used by both the freeDiameter daemon and its extensions.
39 *
40 * It provides the tools to manipulate Diameter messages and related data. 39 * It provides the tools to manipulate Diameter messages and related data.
41 *
42 * This file should always be included as #include <freeDiameter/libfreeDiameter.h> 40 * This file should always be included as #include <freeDiameter/libfreeDiameter.h>
41 *
42 * The file contains the following parts:
43 * DEBUG
44 * MACROS
45 * THREADS
46 * LISTS
47 * DICTIONARY
48 * SESSIONS
49 * MESSAGES
50 * DISPATCH
51 * QUEUES
43 */ 52 */
44 53
45 #ifndef _LIBFREEDIAMETER_H 54 #ifndef _LIBFREEDIAMETER_H
46 #define _LIBFREEDIAMETER_H 55 #define _LIBFREEDIAMETER_H
47 56
294 #define sSS struct sockaddr_storage 303 #define sSS struct sockaddr_storage
295 #define sSA struct sockaddr 304 #define sSA struct sockaddr
296 #define sSA4 struct sockaddr_in 305 #define sSA4 struct sockaddr_in
297 #define sSA6 struct sockaddr_in6 306 #define sSA6 struct sockaddr_in6
298 307
299 /* Dump one sockaddr */ 308 /* Dump one sockaddr Node information */
300 #define sSA_DUMP( level, text, sa ) { \ 309 #define sSA_DUMP_NODE( sa, flag ) { \
301 sSA * __sa = (sSA *)(sa); \ 310 sSA * __sa = (sSA *)(sa); \
302 char *__str, __addrbuf[INET6_ADDRSTRLEN]; \ 311 char __addrbuf[INET6_ADDRSTRLEN]; \
303 if (__sa) { \ 312 if (__sa) { \
304 int __rc = getnameinfo(__sa, \ 313 int __rc = getnameinfo(__sa, \
305 sizeof(sSS), \ 314 sizeof(sSS), \
306 __addrbuf, \ 315 __addrbuf, \
307 sizeof(__addrbuf), \ 316 sizeof(__addrbuf), \
308 NULL, \ 317 NULL, \
309 0, \ 318 0, \
310 0); \ 319 flag); \
311 if (__rc) \ 320 if (__rc) \
312 __str = (char *)gai_strerror(__rc); \ 321 fd_log_debug((char *)gai_strerror(__rc)); \
313 else \ 322 else \
314 __str = &__addrbuf[0]; \ 323 fd_log_debug(&__addrbuf[0]); \
315 } else { \ 324 } else { \
316 __str = "(NULL / ANY)"; \ 325 fd_log_debug("(NULL / ANY)"); \
317 } \ 326 } \
318 TRACE_DEBUG(level, text "%s", __str); \
319 } 327 }
328 /* if needed, add sSA_DUMP_SERVICE */
320 329
321 /* The sockaddr length of a sSS structure */ 330 /* The sockaddr length of a sSS structure */
322 #define sSSlen( _ss_ ) \ 331 #define sSSlen( _ss_ ) \
323 ( (socklen_t) ( ((_ss_)->ss_family == AF_INET) ? (sizeof(sSA4)) : \ 332 ( (socklen_t) ( ((_ss_)->ss_family == AF_INET) ? (sizeof(sSA4)) : \
324 (((_ss_)->ss_family == AF_INET6) ? (sizeof(sSA6)) : \ 333 (((_ss_)->ss_family == AF_INET6) ? (sizeof(sSA6)) : \
2272 int fd_msg_dispatch ( struct msg ** msg, struct session * session, enum disp_action *action ); 2281 int fd_msg_dispatch ( struct msg ** msg, struct session * session, enum disp_action *action );
2273 2282
2274 2283
2275 2284
2276 /*============================================================*/ 2285 /*============================================================*/
2277 /* MESSAGE QUEUES */ 2286 /* QUEUES */
2278 /*============================================================*/ 2287 /*============================================================*/
2279 2288
2280 /* Management of queues of messages */ 2289 /* Management of FIFO queues of elements */
2281 2290
2282 /* A message queue is an opaque object */ 2291 /* A queue is an opaque object */
2283 struct mqueue; 2292 struct fifo;
2284 2293
2285 /* 2294 /*
2286 * FUNCTION: fd_mq_new 2295 * FUNCTION: fd_fifo_new
2287 * 2296 *
2288 * PARAMETERS: 2297 * PARAMETERS:
2289 * queue : Upon success, a pointer to the new message queue is saved here. 2298 * queue : Upon success, a pointer to the new queue is saved here.
2290 * 2299 *
2291 * DESCRIPTION: 2300 * DESCRIPTION:
2292 * Create a new empty message queue. 2301 * Create a new empty queue.
2293 * 2302 *
2294 * RETURN VALUE : 2303 * RETURN VALUE :
2295 * 0 : The message queue has been initialized successfully. 2304 * 0 : The queue has been initialized successfully.
2296 * EINVAL : The parameter is invalid. 2305 * EINVAL : The parameter is invalid.
2297 * ENOMEM : Not enough memory to complete the creation. 2306 * ENOMEM : Not enough memory to complete the creation.
2298 */ 2307 */
2299 int fd_mq_new ( struct mqueue ** queue ); 2308 int fd_fifo_new ( struct fifo ** queue );
2300 2309
2301 /* 2310 /*
2302 * FUNCTION: fd_mq_del 2311 * FUNCTION: fd_fifo_del
2303 * 2312 *
2304 * PARAMETERS: 2313 * PARAMETERS:
2305 * queue : Pointer to an empty message queue to delete. 2314 * queue : Pointer to an empty queue to delete.
2306 * 2315 *
2307 * DESCRIPTION: 2316 * DESCRIPTION:
2308 * Destroys a message queue. This is only possible if no thread is waiting for a message, 2317 * Destroys a queue. This is only possible if no thread is waiting for an element,
2309 * and the queue is empty. 2318 * and the queue is empty.
2310 * 2319 *
2311 * RETURN VALUE: 2320 * RETURN VALUE:
2312 * 0 : The message queue has been destroyed successfully. 2321 * 0 : The queue has been destroyed successfully.
2313 * EINVAL : The parameter is invalid. 2322 * EINVAL : The parameter is invalid.
2314 */ 2323 */
2315 int fd_mq_del ( struct mqueue ** queue ); 2324 int fd_fifo_del ( struct fifo ** queue );
2316 2325
2317 /* 2326 /*
2318 * FUNCTION: fd_mq_length 2327 * FUNCTION: fd_fifo_length
2319 * 2328 *
2320 * PARAMETERS: 2329 * PARAMETERS:
2321 * queue : The queue from which to retrieve the length. 2330 * queue : The queue from which to retrieve the number of elements.
2322 * length : Upon success, the current number of messages in the queue is stored here. 2331 * length : Upon success, the current number of elements in the queue is stored here.
2323 * 2332 *
2324 * DESCRIPTION: 2333 * DESCRIPTION:
2325 * Retrieve the number of messages pending in a queue. 2334 * Retrieve the number of elements in a queue.
2326 * 2335 *
2327 * RETURN VALUE: 2336 * RETURN VALUE:
2328 * 0 : The length of the queue has been written. 2337 * 0 : The length of the queue has been written.
2329 * EINVAL : A parameter is invalid. 2338 * EINVAL : A parameter is invalid.
2330 */ 2339 */
2331 int fd_mq_length ( struct mqueue * queue, int * length ); 2340 int fd_fifo_length ( struct fifo * queue, int * length );
2332 int fd_mq_length_noerr ( struct mqueue * queue ); /* alternate with no error checking */ 2341 int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */
2333 2342
2334 /* 2343 /*
2335 * FUNCTION: fd_mq_setthrhd 2344 * FUNCTION: fd_fifo_setthrhd
2336 * 2345 *
2337 * PARAMETERS: 2346 * PARAMETERS:
2338 * queue : The queue for which the thresholds are being set. 2347 * queue : The queue for which the thresholds are being set.
2339 * data : An opaque pointer that is passed to h_cb and l_cb callbacks. 2348 * data : An opaque pointer that is passed to h_cb and l_cb callbacks.
2340 * high : The high-level threshold. If the number of elements in the queue increase to this value, h_cb is called. 2349 * high : The high-level threshold. If the number of elements in the queue increase to this value, h_cb is called.
2342 * low : The low-level threshold. Must be < high. 2351 * low : The low-level threshold. Must be < high.
2343 * l_cb : If the number of elements decrease to low, this callback is called. 2352 * l_cb : If the number of elements decrease to low, this callback is called.
2344 * 2353 *
2345 * DESCRIPTION: 2354 * DESCRIPTION:
2346 * This function allows to adjust the number of producer / consumer threads of a queue. 2355 * This function allows to adjust the number of producer / consumer threads of a queue.
2347 * If the consumer are slower than the producers, the number of messages in the queue increase. 2356 * If the consumer are slower than the producers, the number of elements in the queue increase.
2348 * By setting a "high" value, we allow a callback to be called when this number is too high. 2357 * By setting a "high" value, we allow a callback to be called when this number is too high.
2349 * The typical use would be to create an additional consumer thread in this callback. 2358 * The typical use would be to create an additional consumer thread in this callback.
2350 * If the queue continues to grow, the callback will be called again when the length is 2 * high, then 3*high, ... N * high 2359 * If the queue continues to grow, the callback will be called again when the length is 2 * high, then 3*high, ... N * high
2351 * (the callback itself may implement a limit on the number of consumers that can be created) 2360 * (the callback itself should implement a limit on the number of consumers that can be created)
2352 * When the queue starts to decrease, and the number of elements go under ((N - 1) * high + low, the l_cb callback is called 2361 * When the queue starts to decrease, and the number of elements go under ((N - 1) * high + low, the l_cb callback is called
2353 * and would typially stop one of the consumer threads. If the queue continue to reduce, l_cb is again called at (N-2)*high + low, 2362 * and would typially stop one of the consumer threads. If the queue continues to reduce, l_cb is again called at (N-2)*high + low,
2354 * and so on. 2363 * and so on.
2355 * 2364 *
2356 * Since there is no destructor for the data pointer, if cleanup operations are required, they should be performed in 2365 * Since there is no destructor for the data pointer, if cleanup operations are required, they should be performed in
2357 * l_cb when the length of the queue is becoming < low. 2366 * l_cb when the length of the queue is becoming < low.
2358 * 2367 *
2359 * Note that the callbacks are called synchronously, during fd_mq_post or fd_mq_get. Their operation should be quick. 2368 * Note that the callbacks are called synchronously, during fd_fifo_post or fd_fifo_get. Their operation should be quick.
2360 * 2369 *
2361 * RETURN VALUE: 2370 * RETURN VALUE:
2362 * 0 : The thresholds have been set 2371 * 0 : The thresholds have been set
2363 * EINVAL : A parameter is invalid. 2372 * EINVAL : A parameter is invalid.
2364 */ 2373 */
2365 int fd_mq_setthrhd ( struct mqueue * queue, void * data, uint16_t high, void (*h_cb)(struct mqueue *, void **), uint16_t low, void (*l_cb)(struct mqueue *, void **) ); 2374 int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) );
2366 2375
2367 /* 2376 /*
2368 * FUNCTION: fd_mq_post 2377 * FUNCTION: fd_fifo_post
2369 * 2378 *
2370 * PARAMETERS: 2379 * PARAMETERS:
2371 * queue : The queue in which the message must be posted. 2380 * queue : The queue in which the element must be posted.
2372 * msg : The message that is put in the queue. 2381 * item : The element that is put in the queue.
2373 * 2382 *
2374 * DESCRIPTION: 2383 * DESCRIPTION:
2375 * A message is added in a queue. Messages are retrieved from the queue (in FIFO order) 2384 * An element is added in a queue. Elements are retrieved from the queue in FIFO order
2376 * with the fd_mq_get, fd_mq_tryget, or fd_mq_timedget functions. 2385 * with the fd_fifo_get, fd_fifo_tryget, or fd_fifo_timedget functions.
2377 * 2386 *
2378 * RETURN VALUE: 2387 * RETURN VALUE:
2379 * 0 : The message is queued. 2388 * 0 : The element is queued.
2380 * EINVAL : A parameter is invalid. 2389 * EINVAL : A parameter is invalid.
2381 * ENOMEM : Not enough memory to complete the operation. 2390 * ENOMEM : Not enough memory to complete the operation.
2382 */ 2391 */
2383 int fd_mq_post ( struct mqueue * queue, struct msg ** msg ); 2392 int fd_fifo_post_int ( struct fifo * queue, void ** item );
2384 2393 #define fd_fifo_post(queue, item) \
2385 /* 2394 fd_fifo_post_int((queue), (void *)(item))
2386 * FUNCTION: fd_mq_get 2395
2387 * 2396 /*
2388 * PARAMETERS: 2397 * FUNCTION: fd_fifo_get
2389 * queue : The queue from which the message must be retrieved. 2398 *
2390 * msg : On return, the first message of the queue is stored here. 2399 * PARAMETERS:
2391 * 2400 * queue : The queue from which the first element must be retrieved.
2392 * DESCRIPTION: 2401 * item : On return, the first element of the queue is stored here.
2393 * This function retrieves a message from a queue. If the queue is empty, the function will block the 2402 *
2394 * thread until a new message is posted to the queue, or until the thread is canceled (in which case the 2403 * DESCRIPTION:
2404 * This function retrieves the first element from a queue. If the queue is empty, the function will block the
2405 * thread until a new element is posted to the queue, or until the thread is canceled (in which case the
2395 * function does not return). 2406 * function does not return).
2396 * 2407 *
2397 * RETURN VALUE: 2408 * RETURN VALUE:
2398 * 0 : A new message has been retrieved. 2409 * 0 : A new element has been retrieved.
2399 * EINVAL : A parameter is invalid. 2410 * EINVAL : A parameter is invalid.
2400 */ 2411 */
2401 int fd_mq_get ( struct mqueue * queue, struct msg ** msg ); 2412 int fd_fifo_get_int ( struct fifo * queue, void ** item );
2402 2413 #define fd_fifo_get(queue, item) \
2403 /* 2414 fd_fifo_get_int((queue), (void *)(item))
2404 * FUNCTION: fd_mq_tryget 2415
2405 * 2416 /*
2406 * PARAMETERS: 2417 * FUNCTION: fd_fifo_tryget
2407 * queue : The queue from which the message must be retrieved. 2418 *
2419 * PARAMETERS:
2420 * queue : The queue from which the element must be retrieved.
2408 * msg : On return, the message is stored here. 2421 * msg : On return, the message is stored here.
2409 * 2422 *
2410 * DESCRIPTION: 2423 * DESCRIPTION:
2411 * This function is similar to fd_mq_get, except that it will not block if 2424 * This function is similar to fd_fifo_get, except that it will not block if
2412 * the queue is empty, but return EWOULDBLOCK instead. 2425 * the queue is empty, but return EWOULDBLOCK instead.
2413 * 2426 *
2414 * RETURN VALUE: 2427 * RETURN VALUE:
2415 * 0 : A new message has been retrieved. 2428 * 0 : A new element has been retrieved.
2416 * EINVAL : A parameter is invalid. 2429 * EINVAL : A parameter is invalid.
2417 * EWOULDBLOCK : The queue was empty. 2430 * EWOULDBLOCK : The queue was empty.
2418 */ 2431 */
2419 int fd_mq_tryget ( struct mqueue * queue, struct msg ** msg ); 2432 int fd_fifo_tryget_int ( struct fifo * queue, void ** item );
2420 2433 #define fd_fifo_tryget(queue, item) \
2421 /* 2434 fd_fifo_tryget_int((queue), (void *)(item))
2422 * FUNCTION: fd_mq_timedget 2435
2423 * 2436 /*
2424 * PARAMETERS: 2437 * FUNCTION: fd_fifo_timedget
2425 * queue : The queue from which the message must be retrieved. 2438 *
2426 * msg : On return, the message is stored here. 2439 * PARAMETERS:
2427 * abstime : the absolute time until which we allow waiting for a message. 2440 * queue : The queue from which the element must be retrieved.
2428 * 2441 * item : On return, the element is stored here.
2429 * DESCRIPTION: 2442 * abstime : the absolute time until which we allow waiting for an item.
2430 * This function is similar to fd_mq_get, except that it will block if the queue is empty 2443 *
2444 * DESCRIPTION:
2445 * This function is similar to fd_fifo_get, except that it will block if the queue is empty
2431 * only until the absolute time abstime (see pthread_cond_timedwait for + info). 2446 * only until the absolute time abstime (see pthread_cond_timedwait for + info).
2432 * If the queue is still empty when the time expires, the function returns ETIMEDOUT 2447 * If the queue is still empty when the time expires, the function returns ETIMEDOUT
2433 * 2448 *
2434 * RETURN VALUE: 2449 * RETURN VALUE:
2435 * 0 : A new message has been retrieved. 2450 * 0 : A new item has been retrieved.
2436 * EINVAL : A parameter is invalid. 2451 * EINVAL : A parameter is invalid.
2437 * ETIMEDOUT : The time out has passed and no message has been received. 2452 * ETIMEDOUT : The time out has passed and no item has been received.
2438 */ 2453 */
2439 int fd_mq_timedget ( struct mqueue * queue, struct msg ** msg, const struct timespec *abstime ); 2454 int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime );
2455 #define fd_fifo_timedget(queue, item, abstime) \
2456 fd_fifo_timedget_int((queue), (void *)(item), (abstime))
2440 2457
2441 #endif /* _LIBFREEDIAMETER_H */ 2458 #endif /* _LIBFREEDIAMETER_H */
"Welcome to our mercurial repository"