comparison include/freeDiameter/libfreeDiameter.h @ 6:b0d377c79d80

Progress on dispatch API spec; added fd_sess_reclaim function and test
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 03 Sep 2009 16:03:25 +0900
parents c2d2729e3603
children e5af94b04946
comparison
equal deleted inserted replaced
5:c2d2729e3603 6:b0d377c79d80
1306 * RETURN VALUE: 1306 * RETURN VALUE:
1307 * 0 : The new handler has been created. 1307 * 0 : The new handler has been created.
1308 * EINVAL : A parameter is invalid. 1308 * EINVAL : A parameter is invalid.
1309 * ENOMEM : Not enough memory to complete the operation 1309 * ENOMEM : Not enough memory to complete the operation
1310 */ 1310 */
1311 int fd_sess_handler_create_int ( struct session_handler ** handler, void (*cleanup)(char * sid, session_state * state) ); 1311 int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(char * sid, session_state * state) );
1312 /* Macro to avoid casting everywhere */ 1312 /* Macro to avoid casting everywhere */
1313 #define fd_sess_handler_create( _handler, _cleanup ) \ 1313 #define fd_sess_handler_create( _handler, _cleanup ) \
1314 fd_sess_handler_create_int( (_handler), (void (*)(char *, session_state *))(_cleanup) ) 1314 fd_sess_handler_create_internal( (_handler), (void (*)(char *, session_state *))(_cleanup) )
1315 1315
1316 /* 1316 /*
1317 * FUNCTION: fd_sess_handler_destroy 1317 * FUNCTION: fd_sess_handler_destroy
1318 * 1318 *
1319 * PARAMETERS: 1319 * PARAMETERS:
1435 * 0 : The session no longer exists. 1435 * 0 : The session no longer exists.
1436 * EINVAL : A parameter is invalid. 1436 * EINVAL : A parameter is invalid.
1437 */ 1437 */
1438 int fd_sess_destroy ( struct session ** session ); 1438 int fd_sess_destroy ( struct session ** session );
1439 1439
1440 /*
1441 * FUNCTION: fd_sess_reclaim
1442 *
1443 * PARAMETERS:
1444 * session : Pointer to a session object.
1445 *
1446 * DESCRIPTION:
1447 * Destroys the resources of a session, only if no session_state is associated with it.
1448 *
1449 * RETURN VALUE:
1450 * 0 : The session no longer exists.
1451 * EINVAL : A parameter is invalid.
1452 */
1453 int fd_sess_reclaim ( struct session ** session );
1454
1455
1440 1456
1441 1457
1442 /* 1458 /*
1443 * FUNCTION: fd_sess_state_store 1459 * FUNCTION: fd_sess_state_store
1444 * 1460 *
1456 * 0 : The state has been stored. 1472 * 0 : The state has been stored.
1457 * EINVAL : A parameter is invalid. 1473 * EINVAL : A parameter is invalid.
1458 * EALREADY : Data was already associated with this session and client. 1474 * EALREADY : Data was already associated with this session and client.
1459 * ENOMEM : Not enough memory to complete the operation 1475 * ENOMEM : Not enough memory to complete the operation
1460 */ 1476 */
1461 int fd_sess_state_store_int ( struct session_handler * handler, struct session * session, session_state ** state ); 1477 int fd_sess_state_store_internal ( struct session_handler * handler, struct session * session, session_state ** state );
1462 #define fd_sess_state_store( _handler, _session, _state ) \ 1478 #define fd_sess_state_store( _handler, _session, _state ) \
1463 fd_sess_state_store_int( (_handler), (_session), (void *)(_state) ) 1479 fd_sess_state_store_internal( (_handler), (_session), (void *)(_state) )
1464 1480
1465 /* 1481 /*
1466 * FUNCTION: fd_sess_state_retrieve 1482 * FUNCTION: fd_sess_state_retrieve
1467 * 1483 *
1468 * PARAMETERS: 1484 * PARAMETERS:
1478 * 1494 *
1479 * RETURN VALUE: 1495 * RETURN VALUE:
1480 * 0 : *state is updated (NULL or points to the state if it was found). 1496 * 0 : *state is updated (NULL or points to the state if it was found).
1481 * EINVAL : A parameter is invalid. 1497 * EINVAL : A parameter is invalid.
1482 */ 1498 */
1483 int fd_sess_state_retrieve_int ( struct session_handler * handler, struct session * session, session_state ** state ); 1499 int fd_sess_state_retrieve_internal ( struct session_handler * handler, struct session * session, session_state ** state );
1484 #define fd_sess_state_retrieve( _handler, _session, _state ) \ 1500 #define fd_sess_state_retrieve( _handler, _session, _state ) \
1485 fd_sess_state_retrieve_int( (_handler), (_session), (void *)(_state) ) 1501 fd_sess_state_retrieve_internal( (_handler), (_session), (void *)(_state) )
1486 1502
1487 1503
1488 /* For debug */ 1504 /* For debug */
1489 void fd_sess_dump(int level, struct session * session); 1505 void fd_sess_dump(int level, struct session * session);
1490 void fd_sess_dump_hdl(int level, struct session_handler * handler); 1506 void fd_sess_dump_hdl(int level, struct session_handler * handler);
1492 1508
1493 /*============================================================*/ 1509 /*============================================================*/
1494 /* DISPATCH */ 1510 /* DISPATCH */
1495 /*============================================================*/ 1511 /*============================================================*/
1496 1512
1497 /* The dispatch process consists in passing a message to some handlers 1513 /* Dispatch module (passing incoming messages to extensions registered callbacks)
1498 (typically provided by extensions) based on its content (app id, cmd code...) */ 1514 * is split between the library and the daemon.
1499 1515 *
1500 /* The dispatch module has two main roles: 1516 * The library provides the support for associating dispatch callbacks with
1517 * dictionary objects.
1518 *
1519 * The daemon is responsible for calling the callbacks for a message when appropriate.
1520 *
1521 *
1522 * The dispatch module has two main roles:
1501 * - help determine if a message can be handled locally (during the routing step) 1523 * - help determine if a message can be handled locally (during the routing step)
1524 * This decision involves only the application-id of the message.
1502 * - pass the message to the callback(s) that will handle it (during the dispatch step) 1525 * - pass the message to the callback(s) that will handle it (during the dispatch step)
1503 * 1526 *
1504 * These are the possibilities for registering a callback: 1527 * These are the possibilities for registering a so-called dispatch callback:
1505 * 1528 *
1506 * -> For All messages. 1529 * -> For All messages.
1507 * This callback is called for all messages that are handled locally. This should be used only 1530 * This callback is called for all messages that are handled locally. This should be used only
1508 * internally by the daemon, or for debug purpose. 1531 * for debug purpose.
1509 * 1532 *
1510 * -> by AVP value (constants). 1533 * -> by AVP value (constants only).
1511 * This callback will be called when a message is received and contains a certain AVP with a specified value. 1534 * This callback will be called when a message is received and contains an AVP with a specified enumerated value.
1512 * 1535 *
1513 * -> by AVP. 1536 * -> by AVP.
1514 * This callback will be called when the received message contains a certain AVP. 1537 * This callback will be called when the received message contains a certain AVP.
1515 * 1538 *
1516 * -> by command-code. 1539 * -> by command-code.
1517 * This callback will be called when the message is a specific command. 1540 * This callback will be called when the message is a specific command (and 'R' flag).
1518 * 1541 *
1519 * -> by application. 1542 * -> by application.
1520 * This callback will be called when the message has a specific application-id. 1543 * This callback will be called when the message has a specific application-id.
1521 * 1544 *
1522 * ( by vendor: would this be useful? it may be added later) 1545 * ( by vendor: would this be useful? it may be added later)
1523 * 1546 */
1524 * Note that several criteria may be selected at the same time, for example command-code AND application id. 1547 enum disp_how {
1525 * 1548 DISP_HOW_ANY = 1, /* Any message. This should be only used for debug. */
1526 * When a callback is called, it receives the message as parameter, and eventually a pointer to 1549 DISP_HOW_APPID, /* Any message with the specified application-id */
1527 * the AVP in the message when this is appropriate. 1550 DISP_HOW_CC, /* Messages of the specified command-code (request or answer). App id may be specified. */
1528 * 1551 DISP_HOW_AVP, /* Messages containing a specific AVP. Command-code and App id may be specified. */
1529 * The callback must process the message, and eventually create an answer to it. See the definition 1552 DISP_HOW_AVP_ENUMVAL /* Messages containing a specific AVP with a specific enumerated value. Command-code and App id may be specified. */
1530 * bellow for more information. 1553 };
1531 * 1554 /*
1532 * If no callback has handled the message, a default handler will be called with the effect of 1555 * Several criteria may be selected at the same time, for example command-code AND application id.
1533 * requeuing the message for forwarding on the network to another peer (for requests, if possible), or 1556 *
1534 * discarding the message (for answers). 1557 * If several callbacks are registered for the same object, their order is unspecified.
1535 */ 1558 * The order in which the callbacks are called is:
1536 1559 * DISP_HOW_ANY
1537 1560 * DISP_HOW_AVP_ENUMVAL & DISP_HOW_AVP
1561 * DISP_HOW_CC
1562 * DISP_HOW_APPID
1563 */
1564
1565 /* When a callback is registered, a "when" argument is passed in addition to the disp_how value,
1566 * to specify which values the criteria must match. */
1567 struct disp_when {
1568 struct dict_object * app_id;
1569 struct dict_object * command;
1570 struct dict_object * avp;
1571 struct dict_object * value;
1572 };
1573
1574 /* Here is the details on this "when" argument, depending on the disp_how value.
1575 *
1576 * DISP_HOW_ANY.
1577 * In this case, "when" must be NULL.
1578 *
1579 * DISP_HOW_APPID.
1580 * Only the "app_id" field must be set, other fields are ignored. It points to a dictionary object of type DICT_APPLICATION.
1581 *
1582 * DISP_HOW_CC.
1583 * The "command" field must be defined and point to a dictionary object of type DICT_COMMAND.
1584 * The "app_id" may be also set. In the case it is set, it restricts the callback to be called only with this command-code and app id.
1585 * The other fields are ignored.
1586 *
1587 * DISP_HOW_AVP.
1588 * The "avp" field of the structure must be set and point to a dictionary object of type DICT_AVP.
1589 * The "app_id" field may be set to restrict the messages matching to a specific app id.
1590 * The "command" field may also be set to a valid DICT_COMMAND object.
1591 * The content of the "value" field is ignored.
1592 *
1593 * DISP_HOW_AVP_ENUMVAL.
1594 * All fields have the same constraints and meaning as in DISP_REG_AVP. In addition, the "value" field must be set
1595 * and points to a valid DICT_ENUMVAL object.
1596 *
1597 * Here is a sumary of the fields: ( M : must be set; m : may be set; 0 : ignored )
1598 * field: app_id command avp value
1599 * APPID : M 0 0 0
1600 * CC : m M 0 0
1601 * AVP : m m M 0
1602 * ENUMVA: m m M M
1603 */
1604
1605 /* The callbacks that are registered have the following prototype:
1606 *
1607 * int dispatch_callback( struct msg ** msg, struct avp * avp, struct session * session, int * is_answer );
1608 *
1609 * FUNCTION: dispatch_callback
1610 *
1611 * PARAMETERS:
1612 * msg : the received message on function entry. may be updated to answer on return (see description)
1613 * avp : for callbacks registered with DISP_HOW_AVP or DISP_HOW_AVP_ENUMVAL, direct link to the triggering AVP.
1614 * session : if the message contains a Session-Id AVP, the corresponding session object.
1615 *
1616 * DESCRIPTION:
1617 * Create a new AVP instance.
1618 *
1619 * RETURN VALUE:
1620 * 0 : The AVP is created.
1621 * EINVAL : A parameter is invalid.
1622 * (other standard errors may be returned, too, with their standard meaning. Example:
1623 * ENOMEM : Memory allocation for the new avp failed.)
1624 */
1538 1625
1539 1626
1540 /*============================================================*/ 1627 /*============================================================*/
1541 /* MESSAGES */ 1628 /* MESSAGES */
1542 /*============================================================*/ 1629 /*============================================================*/
"Welcome to our mercurial repository"